Is there a way to specify which dimensions I want dot to work over?
For example, if I have two arrays:
In [78]:ma = array([4,5,6]) # shape = (1,3)
In [79]:mb = ma.transpose() # shape = (3,1)
In [80]:dot(mb,ma)
Out[80]:
array([[16, 20, 24],
[20, 25, 30],
[24, 30, 36]])
No problems there.
Now I want to do that multiple times, threading over the first dimension
of larger arrays:
In [85]:mc = array([[[4,5,6]],[[7,8,9]]]) # shape = (2, 1, 3)
In [86]:md = array([[[4],[5],[6]],[[7],[8],[9]]]) #shape = (2, 3, 1)
and I want to calculate the two (3, 1) x (1, 3) dot products to get a
shape = (2, 3, 3) result, so that
res[i,...] == dot(md[i,...], mc[i,...])
>From my example above res[0,...] would be the same as dot(mb,ma) and
res[1,...] would be
In [108]:dot(md[1,...],mc[1,...])
Out[108]:
array([[49, 56, 63],
[56, 64, 72],
[63, 72, 81]])
I could do it by explicitly looping over the first dimension (as
suggested by my generic example), but it seems like there should be a
better way by specifying to the dot function the dimensions over which
it should be 'dotting'.
Cheers,
Angus.
--
Angus McMorland
email a.mcmorland(a)auckland.ac.nz
mobile +64-21-155-4906
PhD Student, Neurophysiology / Multiphoton & Confocal Imaging
Physiology, University of Auckland
phone +64-9-3737-599 x89707
Armourer, Auckland University Fencing
Secretary, Fencing North Inc.