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

Alexander Michael lxander.m@gmail....
Wed Mar 14 12:31:54 CDT 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