Questions tagged [elementwise-operations]

204 questions
2
votes
1 answer

Torch Element-wise Logical Operation and/or

I am trying to perform logical element-wise opertaions on tensors, but it seems "and" keyword performs logical or, while "or" keyword performs logical and : a = torch.zeros(3) a[1] = 1 -- a will be [1,0,0] b =…
kerrigan
  • 87
  • 2
  • 9
2
votes
1 answer

Sparse matrix multiplication in MATLAB with spfun

I have a dense column matrix y of size (m,1) and a sparse matrix x of size (m,n). I want to do element-wise multiplication using y and every column of x. The resultant sparse matrix is still of size (m,n). Sparse matrix x, when loaded into memory,…
user3630879
2
votes
1 answer

Efficient 3D element-wise operations in MATLAB

Say i have two martrices: A=50; B=50; C=1000; X = rand(A,B); Y = rand(A,B,C); I want to subtract X from each slice C of Y. This is a fairly common problem and i have found three alternative solutions: % Approach 1: for-loop tic Z1 =…
2
votes
3 answers

Mathematica: adding a list of lists elementwise

I have a list of lists of numbers. I add them into one list by adding all of the first elements together, all of the second elements together, etc. For example, if my list were { {1,2,3}, {1,2,3}, {1,2,3,4} } I would want to end up with {3,6,9,4}.…
2
votes
1 answer

Compare OpenCV Mat with scalar elementwise

I have a cv::Mat A, which has CV_32F. However it holds integer values like 1,2....100. I want to form a mask of same size as A. But the mask must contain zeros if A(x,y) not equal to 5 (say). The mask must contain ones if A(x,y) equal to 5 (say). I…
mkuse
  • 2,250
  • 4
  • 32
  • 61
2
votes
2 answers

Calculating the powers of a vector elementwise

I have a vector [x, y, ...] in Octave and I would like to take the pth powers of the elements to get the new vector [x^p, y^p, ...]. Anybody has an idea how to do this?
1
vote
1 answer

How do I collapse (element-wise for maximum, minimum, or mean) a multi-dimensional numpy array for a subset of indices along a specific axis?

I currently have a numpy array of the shape (71, 136, 136, 130); the exact dimensions vary. This is volume data (e.g., temperature) in the form [Time, Z, Y, X]. I am allowing the user to specify the time range to collapse the Z, Y, X volume…
wein3967
  • 45
  • 4
1
vote
0 answers

Elementwise Comparison of Numpy Arrays

I would like to ask a question for the table below for the comparison of np arrays: Ticket Travel Time Price A 10 1700 B 9 2000 C 8 1800 D 7.5 2300 E 6 …
1
vote
1 answer

Writing {value} +- {uncertainty} in matrix. How does that work with sympy?

I have two 6x6 matrices. Here I'll just show the first two rows and columns: import sympy as sp values = sp.Matrix([[-0.403900000000000, 0.158730000000000], [-1.52350000000000, -1.87937000000000]]) uncertainties = sp.Matrix([[0.000600000000000000,…
Tasha
  • 13
  • 3
1
vote
1 answer

How do I do an elementwise sum of the current element and next three row elements (in column 0) using array operations not a for loop?

I am trying to do an operation relative to the location of the element during an elementwise numpy operation. I cannot figure out how access the current location in order to sum it with the next three elements. I have included a sample array as…
1
vote
2 answers

Python namedtuples elementwise addition

Is there a more pythonic way to implement elementwise addition for named tuples? Using this class that inherits from a namedtuple generated class named "Point I can do elementwise addition for this specific named tuple. class…
1
vote
1 answer

Problem with element-wise operations in numpy

This is my first Question here, let me know if I could've done anything better. I'm trying to do a element-wise operation between two arrays, but the broadcasting wont work like I want it to. I have an array of shape (N,4). square_list =…
1
vote
3 answers

element-wise averages of two (or more) nested lists of matrices

I have two lists A_1 and A_2, each contains two matrices. A_1 <- list(a=matrix(1:8, 2), b=matrix(2:9, 2)) A_2 <- list(a=matrix(10:17, 2), b=matrix(5:12, 2)) I'd like to calculate element-wise averages of these two lists which results a list…
hnguyen
  • 772
  • 6
  • 17
1
vote
1 answer

per-element vector multiplication with gurobipy

The last line of this code fails: A = np.random.rand(d, d)*5.0 b = np.random.rand(d)*10.0 m = gp.Model() x = m.addMVar(d, name='x') y = m.addMVar(d, name='y', vtype=gp.GRB.BINARY) m.addConstr(A@x <= b) m.addConstr(A@x >= y*b) // error occurs here on…
Brannon
  • 5,324
  • 4
  • 35
  • 83
1
vote
1 answer

Calculating the differences between series of correlation matrixes (as DataFrames, pandas) in python

From a series of DataFrames that contain daily log returns of a large number of stocks, eg: data_list = [data_2015, data_2016, data_2017, data_2018, data_2019, data_2020] The task at hand is to compute the change in the correlations between each…