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

Charles R Harris charlesr.harris at gmail.com
Wed Jul 9 17:44:13 EDT 2008


On Wed, Jul 9, 2008 at 3:26 PM, Anne Archibald <peridot.faceted at gmail.com>
wrote:

> 2008/7/9 Charles R Harris <charlesr.harris at gmail.com>:
> >
> > On Wed, Jul 9, 2008 at 2:34 PM, Marlin Rowley <marlin_rowley at 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.
>
> This particular instance can be viewed as a matrix multiplication
> (np.dot(A.reshape((-1,3)),v) I think).


Yep, that should work.

Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20080709/d3b05985/attachment.html>


More information about the NumPy-Discussion mailing list