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

Anne Archibald peridot.faceted@gmail....
Wed Jul 9 16:26:11 CDT 2008

```2008/7/9 Charles R Harris <charlesr.harris@gmail.com>:
>
> 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.

This particular instance can be viewed as a matrix multiplication
(np.dot(A.reshape((-1,3)),v) I think).

Anne
```