Multiplication/division Of 2d Numpy Arrays To Produce 3d Array
I am looking for a fast (ie vectorized) method to replace the following loop. I have 2 numpy arrays with dimensions: (20738,14) and (31,14). I need to multiply them element-wise to
Solution 1:
Just use broadcasting:
v.shape
# (20738, 14)
MU.shape
# (31, 14)
v_mu_3d = v[:, None, :] * MU
p2_3d = v[:, None, :] / MU
v_mu_3d.shape
# (20738, 31, 14)
p2_3d.shape
# (20738, 31, 14)
Post a Comment for "Multiplication/division Of 2d Numpy Arrays To Produce 3d Array"