[SciPy-user] Vectorization question
Travis Oliphant
oliphant@ee.byu....
Mon Feb 12 11:09:43 CST 2007
Anand Patil wrote:
>>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
>>
>>
>
>
>The output array I'm looking for is rank-3, but as I understand them dot and tensordot can only ever return even-rank arrays:
>
>
>
I see the difference now. Yes, you are right, you are wanting to do a
sum of products without an outer-product. You would have to extract the
"diagonal" of the result.
-Travis
More information about the SciPy-user
mailing list