Questions tagged [elementwise-operations]
204 questions
1
vote
1 answer
How to multiply a sparse matrix by a sparse matrix element-wise in pytorch
In pytorch, I can achieve two sparse matrixes multiplication by first turning them into a dense form
adjdense = torch.sparse.FloatTensor(indextmp, valuetmp, torch.Size([num_nodes,num_nodes])).to_dense()
mask_dense =…

Unicion
- 11
- 2
1
vote
2 answers
Pandas Element-Wise Variability by Rows using Monthly Averages
I have a df called "df" that looks like this:
year month adjusted_power
333 2018 10 4
334 2018 11 2
335 2018 12 1
336 2019 01 6
337 2019 02 8
338 2019 03 2
339 2019 04 …

user2100039
- 1,280
- 2
- 16
- 31
1
vote
1 answer
Numpy given two arrays with values and confidence create an array of highest confidence values
I want to pick the values from highest confidence model elementwise
vals1 = np.array( [0, 0, 11, 12, 0, 0, 13, 14]) # predicted values using method 1
probs1 = np.array([0.9, 0.8, 0.7, 0.6, 0.5, 0.4, 0.3, 0.2]) # predicted values using method 1
vals2…

Stepan
- 1,391
- 18
- 40
1
vote
1 answer
Accumulate 2D numpy arrays into a 3D tensor, then average them all element-wise after
Accumulation stage
In the script, the same-sized data matrix X is re-estimated by some model (here just a random number generator (RNG)) and accumulated/saved in a matrix Y over the course of a finite number of trials t.
import numpy as np
from…

develarist
- 1,224
- 1
- 13
- 34
1
vote
0 answers
Easier way to do element- wise matrix multiplication for pairs in a given matrix in R?
I have a matrix of dimension n*k and I am trying to calculate another matrix which has all the pairs which will have n(n-1)/2 rows and k columns
New columns are element-wise multiplication of two different individual rows.
Below is the code,how i am…

heisenbug47
- 176
- 1
- 12
1
vote
1 answer
Element-wise sum of nested lists
I have a nested list called list_6:
[[-1, 1, -1, 1, -1, 1, 1, 0, -1, 0, -1, -1, 1, 1, 1, 0, 1, -1, -1, -1, 1, 1, 1, 0, 0, -1, 0, 0, 0, 1, 0, -1, 1, 1, -1, 0, 0, 1, 1, -1, 0, -1, 1, 1, -1, 1, -1, -1, -1, 1, -1],...]]
each element of the list contains…

AndrewLittle1
- 131
- 8
1
vote
2 answers
What the best way to find minimal difference and corresponding value with element-wise vector comparison?
I have one problem.
Vector A is the query, Vector B is the ref.
I want to see which value of A is the closest to one of the B value.
Both vectors are ordered.
INPUT
A = c(1, 1.2, 4, 8, 9, 10, 30)
B = c(0.1, 3.9)
OUTPUT
min_diff_value =…

S.Br
- 33
- 4
1
vote
2 answers
How to use divides and for_each?
I have:
vector ved1 = { 1,2,3,4,5,6,7,8,9,10 };
vector ved2 = { 11,12,13,14,15,16,17,18,19,20 };
vector ved3(10);
and I want to have ved3=ved3/2 but I can't get it correctly, the result is 2/ved3;
How to use…

Youshikyou
- 365
- 1
- 8
1
vote
1 answer
keep getting 'only length-1 arrays can be converted to python scalars'
I keep getting the error only length-1 arrays can be converted to Python scalars. I am getting error due to the variable 'uc' as it is an array of 214 elements.
The error states:
File…

Lokesh
- 35
- 1
- 8
1
vote
4 answers
How to perform element-wise arithmetic operations (e.g. add, subtract, multiply) of two equally shaped lists with arbitrary nestings
I want to perform element-wise mathematical operations (e.g. sum, multiply..) on two Python lists containing numbers or multiple nested lists which may contain again numbers or lists and so on.
The shapes of the two lists are equal when performing…

R3n3
- 31
- 6
1
vote
1 answer
Pytorch batch matrix-matrix outer product
Similarly to the question in Pytorch batch matrix vector outer product I have two matrices and would like to compute their outer product, or in other words the pairwise elementwise product.
Shape example:
If we have X1 and X2 of shapes of…

Codevan
- 538
- 3
- 20
1
vote
1 answer
GPU Array multiplications using Pycuda on Numpy arrays
I have tried to implement Element-wise multiplication of two numpy arrays by making similar GPU arrays and performing the operations. However, the resulting execution time is much slower than the original numpy pointwise multiplication. I was hoping…

Killbill
- 11
- 3
1
vote
1 answer
Is there any way to compute the Hadamard product of COO sparse matrices leveraging its structure?
I am trying to compute the Hadamard product of two matrices stored in COO-sparse format (in SciPy). There's a lecture that reads
fast and easy item-wise operations, manipulate data array directly (fast NumPy machinery)
I understand the sum and…

Jonathan Chang
- 11
- 2
1
vote
1 answer
hadamard product of uneven shaped arrays
I'm doing a whole bunch of hadamard products, as part of a machine learning project. To convey the problem, below is the setup:
# shape: (2, 3)
In [17]: arr1
Out[17]:
array([[0.44486617, 0.21001534, 0.63833794],
[0.90878526, 0.61692562,…

kmario23
- 57,311
- 13
- 161
- 150
1
vote
0 answers
python numpy pinv for each sub-matrix
I need to do a pseudo-inverse(np.linalg.pinv) for each (6,4) in (5,4,6,4). However, I didn't find the designed module to solve this problem and I don't want to use the inefficient for loop. What should I do with it?
I think this would be a common…

Michael Sun
- 61
- 5