I have two arrays that look as follows:
In code that is:
t = np.random.rand(6, 6, 2)
I now want to compute the dot product of the axis 2 arrays (the ones of shape 2), for each of the entries of the axis 0 and 1 arrays.
I can do it with a for loop:
Q = np.zeros_like(t)
for i in range(6):
for j in range(6):
Q[i,j] = t[i,j].dot(t[i,j])
How can I do this with numpy functions?
I could not get it to work with .dot
, .tensordot
or similar methods...
t.dot(t)
produces this error ValueError: shapes (6,6,2) and (6,6,2) not aligned: 2 (dim 2) != 6 (dim 1)
which is to be expected, however I would like to circumvent it.