[Numpy-discussion] Multiplying every 3 elements by a vector?

Charles R Harris charlesr.harris@gmail....
Wed Jul 9 16:17:24 CDT 2008


On Wed, Jul 9, 2008 at 2:34 PM, Marlin Rowley <marlin_rowley@hotmail.com>
wrote:

> Thanks Chuck, but I wasn't quit clear with my question.
>
> You answered exactly according to what I asked, but I failed to mention
> needing the dot product instead of just the product.
>
> So,
>
> v dot A = v'
>
> v'[0] = v[0]*A[0] + v[1]*A[1] + v[2]*A[2]
> v'[1] = v[0]*A[3] + v[1]*A[4] + v[2]*A[5]
> v'[2] = v[0]*A[6] + v[1]*A[7] + v[2]*A[8]
>
>

There is no built in method for this specific problem (stacks of vectors and
matrices), but you can make things work:

sum(A.reshape((-1,3))*v, axis=1)

You can do lots of interesting things using such manipulations and newaxis.
For instance, multiplying stacks of matrices by stacks of matrices etc. I
put up a post of such things once if you are interested.

Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20080709/e5621d56/attachment.html 


More information about the Numpy-discussion mailing list