On Tue, Feb 3, 2009 at 10:19 AM, Gideon Simpson <simp...@math.toronto.edu>wrote:
> I have an M x N matrix A and two vectors, an M dimensional vector x > and an N dimensional vector y. I would like to be able to do two > things. > > 1. Multiply, elementwise, every column of A by x > > 2. Multiply, elementwise, every row of A by y. > > What's the "quick" way to do this in numpy? > In [1]: M = ones((3,3)) In [2]: x = arange(3) In [3]: M*x Out[3]: array([[ 0., 1., 2.], [ 0., 1., 2.], [ 0., 1., 2.]]) In [4]: x[:,newaxis]*M Out[4]: array([[ 0., 0., 0.], [ 1., 1., 1.], [ 2., 2., 2.]]) Chuck
_______________________________________________ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion