[Numpy-discussion] Vectorization of the product of several matrices ?
Charles R Harris
Wed Oct 1 20:42:36 CDT 2008
On Wed, Oct 1, 2008 at 7:16 PM, Charles R Harris
> On Wed, Oct 1, 2008 at 2:46 PM, oc-spam66 <firstname.lastname@example.org> wrote:
>> Hello and thank you for your answer.
>> > There are at least three methods I can think of, but choosing the best
>> > requires more information. How long are the lists? Do the arrays have
>> > variable dimensions? The simplest and most adaptable method is probably
>> The lists would be made of 4x4 matrices :
>> LM = [M_i, i=1..N], M_i 4x4 matrix
>> LN = [N_i, i=1..N], N_i 4x4 matrix.
>> N would be 1000 or more (why not 100000... if the computation is not too
>> > In : P = [m*n for m,n in zip(M,N)]
>> Thank you for this one. I am curious about other possibilities.
> For stacks of small matrices of same dimensions stored in three dimensional
> arrays (not matrices), you can do
> In : M = array([eye(4)]*2)
> In : N = array([eye(4)]*2)
> In : P = (M[...,:,:,newaxis]*N[...,newaxis,::]).sum(axis=-2)
In : P = (M[...,:,:,newaxis]*N[...,newaxis,:,:]).sum(axis=-2)
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Numpy-discussion