[Numpy-discussion] Multiplying Each Column of a Matrix by a Vector (Element-Wise)

Alexander Michael lxander.m at gmail.com
Wed Mar 14 13:31:54 EDT 2007


Is there a clever way to multiply each column of a matrix by a vector
*element-wise*? That is, the equivalent of (from some 1D v and 2D m):

r = numpy.empty_like(m)
for i in range(m.shape[-1]):
    r[...,i] = v*m[...,i]

Thanks,
Alex



More information about the NumPy-Discussion mailing list