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

2008-07-09 Thread Charles R Harris
On Wed, Jul 9, 2008 at 3:26 PM, Anne Archibald <[EMAIL PROTECTED]>
wrote:

> 2008/7/9 Charles R Harris <[EMAIL PROTECTED]>:
> >
> > On Wed, Jul 9, 2008 at 2:34 PM, Marlin Rowley <[EMAIL PROTECTED]
> >
> > 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
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


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

2008-07-09 Thread Anne Archibald
2008/7/9 Charles R Harris <[EMAIL PROTECTED]>:
>
> On Wed, Jul 9, 2008 at 2:34 PM, Marlin Rowley <[EMAIL PROTECTED]>
> 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
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


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

2008-07-09 Thread Charles R Harris
On Wed, Jul 9, 2008 at 2:34 PM, Marlin Rowley <[EMAIL PROTECTED]>
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
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


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

2008-07-09 Thread Marlin Rowley
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]
 
-M



Date: Wed, 9 Jul 2008 13:26:01 -0600From: [EMAIL PROTECTED]: [EMAIL PROTECTED]: 
Re: [Numpy-discussion] Multiplying every 3 elements by a vector?
On Wed, Jul 9, 2008 at 1:16 PM, Marlin Rowley <[EMAIL PROTECTED]> wrote:

All: I'm trying to take a constant vector:  v = (0.122169, 0.61516, 0.262671) 
and multiply those values by every 3 components in an array of length N: A = 
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ] So what I want is:  
v[0]*A[0]v[1]*A[1]v[2]*A[2]v[0]*A[3]v[1]*A[4]v[2]*A[5]v[0]*A[6] ... How do I do 
this with one command in numPy? 
If the length of A is divisible by 3:A.reshape((-1,3))*vYou might want to 
reshape the result to 1-D.Chuck 
_
Use video conversation to talk face-to-face with Windows Live Messenger.
http://www.windowslive.com/messenger/connect_your_way.html?ocid=TXT_TAGLM_WL_Refresh_messenger_video_072008___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


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

2008-07-09 Thread Charles R Harris
On Wed, Jul 9, 2008 at 1:16 PM, Marlin Rowley <[EMAIL PROTECTED]>
wrote:

> All:
>
> I'm trying to take a constant vector:
>
>  v = (0.122169, 0.61516, 0.262671)
>
> and multiply those values by every 3 components in an array of length N:
>
> A = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ]
>
> So what I want is:
>
> v[0]*A[0]
> v[1]*A[1]
> v[2]*A[2]
> v[0]*A[3]
> v[1]*A[4]
> v[2]*A[5]
> v[0]*A[6]
>
> ...
>
> How do I do this with one command in numPy?
>
>

If the length of A is divisible by 3:

A.reshape((-1,3))*v

You might want to reshape the result to 1-D.

Chuck
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion