[SciPy-user] Vectorization question

Travis Oliphant oliphant@ee.byu....
Fri Feb 9 16:20:22 CST 2007


Anand Patil wrote:

>Hi all,
>
>I want to make array A from array B like so:
>
>A[t, j, k] = \sum_i B[t, j, i] B[t, i, k]
>
>That is, for each t
>
>A[t,] = dot(B[t,], B[t,])
>
>There's no loopless way to do this in numpy, right?
>  
>
You should be able to do this just using

A = dot(B,B)

Because the dot function returns the sum of products over the last 
dimension of the first argument and the second-to-last dimension of the 
second argument.

-Travis



More information about the SciPy-user mailing list