Closed
Description
If I try to do
a = np.random.randn(3,3,3,3)
ans1 = np.einsum('iijj',a)
I get a ValueError
:
>>> ValueError: dimensions in operand 0 for collapsing index 'j' don't match (0 != 3)
However, these alternatives work:
ans2 = np.einsum('ii', np.einsum('ijkk', a))
ans3 = np.einsum('ijij', np.einsum('ijkl->ikjl',a))
ans2 == ans3
>>> True
And these agree with the naive version up to the last decimal place
ans4 = 0.0
for i in xrange(3):
for j in xrange(3):
ans4 += a[i,i,j,j]
np.allclose(ans2, ans4) and np.allclose(ans3, ans4)
>>> True
Metadata
Metadata
Assignees
Labels
No labels