Einsum double contraction in particular order causes ValueError
See original GitHub issueIf 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
Issue Analytics
- State:
- Created 9 years ago
- Comments:8 (6 by maintainers)
Top Results From Across the Web
python - Understanding NumPy's einsum - Stack Overflow
Imagine that we have two multi-dimensional arrays, A and B . Now let's suppose we want to... multiply A with B in a...
Read more >NumPy 1.9.1 Release Notes
The second order behaviour is available via the edge_order keyword ... gh-5147: Einsum double contraction in particular order causes ValueError.
Read more >numpy/test_einsum.py at main - GitHub
assert_raises(TypeError, np.einsum, "", 0, out='test',. optimize=do_opt). # order parameter must be a valid order. assert_raises(ValueError, np.einsum, ...
Read more >Source code for opt_einsum.contract
Contains the primary optimization and contraction routines. ... output. dtype : str The dtype of the given contraction, see np.einsum. order : str...
Read more >A basic introduction to NumPy's einsum - ajcr
sum this new array along particular axes, and/or; transpose the axes of the array in a particular order. Then there's a good chance...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Could there be a regression of this bug?
returns
ValueError: dimensions in operand 0 for collapsing index 'd' don't match (1 != 2)
.Summing
b
andc
separately works as do the following examples:@mfdgroot That would be good.