Questions tagged [elementwise-operations]
204 questions
1
vote
1 answer
Python3 Numpy multiply : Could not broadcast together with shapes (10, 10000) (10000, 10)
I'm having an issue using numpy in python3 at this instruction:
res = ( np.multiply(error, v_sigmop ))
I'm trying to multiply element-wise but I'm having this weird error :
res = ( np.multiply(error, v_sigmop ))
ValueError: operands could not be…

Irchad
- 37
- 1
- 5
1
vote
1 answer
Conditional elementwise multiplication of two pandas dataframes
I am struggling doing a basic conditional elementwise multiplication between two dataframes.
Let's assume I have the following two dataframes:
df1 = pd.DataFrame({'A': [-0.1,0.3,-0.4, 0.8,-0.5,-0.1,0.3,-0.4, 0.8,-1.2],'B':…

CTXR
- 139
- 1
- 9
1
vote
3 answers
Python - double loop for element wise string concatenation
My question is very simple:
I have A = ['AA','BB'], B = ['CC','DD']
How do I get AB = ['AACC','AADD','BBCC',BBDD']?
Thank you!

g_tenga
- 51
- 7
1
vote
1 answer
Divide the values from a matrix by another matrix if the conditions are true
I have three data frames with values. They are related to each other and have the same column names but show different things.
dat1 = cbind(a = c(2,1,3),
b = c(2,2,3),
c = c(2,2,2))
a b c
[1,] 2 2 2
[2,] 1 2…

Mataunited18
- 598
- 1
- 7
- 20
1
vote
0 answers
Elementwise multplication with numpy.multiply
Let's say I have a N × 1 × 1 array a, and N × M × M array b as NumPy arrays. I want to do the elementwise multiplication:
c[i,:,:] = a[i]*b[i,:,:]
without iterating over i. The function np.multiply(a,b) seems to do the job. However, I do not quite…

Sina
- 401
- 5
- 12
1
vote
0 answers
Entry-wise constraints in CVXPY
I try to impose some elementwise constraints to the optimization variable using cvxpy. Here is the code:
import cvxpy as cv
import numpy as np
import scipy.io as spio
mat = spio.loadmat('data.mat', squeeze_me=True)
zigma_bar_region1_normal =…

farid
- 11
- 3
1
vote
2 answers
Elementwise comparison of numpy arrays of different lengths
This seems like a simple thing to do but I could not figure it out...
first = np.array([0,1,2,0,4,2])
second = np.array([1,2])
I'd like to do element-wise comparison so that the answer will be
array([False, True, True, False, False, True],…

puifais
- 738
- 2
- 9
- 20
1
vote
1 answer
pandas series elementwise muplication
I have two pandas series a and b as follows:
a = pd.series([1, 2, 3])
b = pd.series([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
What I want to get is a third pandas series as follows:
[[1, 2, 3], [8, 10, 12], [21, 24, 27]]
I have tried the following…

CathyQian
- 1,081
- 15
- 30
1
vote
1 answer
Caffe Element-Wise multiplication with fixed blobs
I think I will be asking multiple quesitons here, I'd love any comment because I'm new to Caffe.
In my network input images have size 1x41x41 Since I am using 64 batch size I think the data size will be 64x1x41x41 (Please correct me if this is…

Tarhan
- 77
- 8
1
vote
2 answers
Python: get the element-wise mean of multiple arrays in a dataframe
I have a 16x10 panda dataframe with 1x35000 arrays (or NaN) in each cell. I want to take the element-wise mean over rows for each column.
1 2 3 ... 10
1 1x35000 1x35000 1x35000 1x35000
2 1x35000 NaN …

Svenno Nito
- 635
- 1
- 6
- 22
1
vote
1 answer
ruby set an array through another array pointing to the original
I have some array deep_array that's deep in a hash and takes time to access, I also have a variable (my_local_variable) pointing to deep_array and some other local array new_array. I need to set deep_array to new_array through…

Asone Tuhid
- 539
- 4
- 13
1
vote
1 answer
Adding specific elements in an Array?
y = np.array([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]])
indices_of_y = np.array([12, 0, 6, 3, 4, 9, 11, 2])
z = np.array([1 , 1, 0, 1, 1, 1, 0, 0])
x = np.array([1, 1, 1, 0, 1, 0, 0, 1])
n =…

Charles B
- 95
- 3
- 14
1
vote
1 answer
Element wise multiplication of each row
I have two DataFrame objects which I want to apply an element-wise multiplication on each row onto:
df_prob_wc.shape # (3505, 13)
df_prob_c.shape # (13, 1)
I thought I could do it with DataFrame.apply()
df_prob_wc.apply(lambda x:…

Stefan Falk
- 23,898
- 50
- 191
- 378
1
vote
1 answer
Are there something in between tensordot and element-wise multiplication in Theano?
Let's assume that we have two tensors (A and B) with the same number of dimensions. We can multiply them with tensordot. For example:
T.tensordot(A, B, axes = [[0,3], [0,3]])
In this case we "pair" axes of the first tensor with some axes of the…

Roman
- 124,451
- 167
- 349
- 456
1
vote
1 answer
How to set 0 x 0 = 1 in a element-wise array multiplication? MATLAB
I have two column vector A and B of same length n.
In both vectors, there are only 3 possible values for their elements: -1, 0 and 1.
When I multiply A by B element-wise, I hope to get the expect results for 1x1, 1x(-1) and (-1)x(-1).
However,…

Jxson99
- 347
- 2
- 16