ValueError with numpy 1.16
See original GitHub issueHi,
Our PRE release bots, which using Numpy 1.16, failed many times with this error:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
(see https://github.com/nipy/dipy/issues/1579)
Here a small example to reproduce our problem:
simple_mp.pyx
file:
import numpy as np
import cython
def masking_test():
simple_wm = np.array([[0, 0, 0, 0, 0, 0],
[0, 0, 1, 0, 0, 0],
[0, 1, 1, 1, 0, 0],
[0, 1, 1, 1, 0, 0],
[0, 0, 0, 0, 0, 0]])
mask = np.zeros(simple_wm.shape)
simple_wm[mask==0] = 1
Test in a Python terminal after compiling:
>>> import simple_mp as m
>>> m.masking_test()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "simple_mp.pyx", line 13, in simple_mp.masking_test
simple_wm[mask==0] = 1
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
Python 3.6 cython 0.29a0 numpy 1.16.0.dev0+2804c03
How can I resolve this problem? Thanks
Issue Analytics
- State:
- Created 5 years ago
- Comments:10 (7 by maintainers)
Top Results From Across the Web
ValueError: numpy.ufunc size changed, may indicate binary ...
python - ValueError: numpy. ufunc size changed, may indicate binary incompatibility. Expected 216 from C header, got 192 from PyObject - Stack ...
Read more >NumPy 1.21.0 Release Notes
The Python versions supported for this release are 3.7-3.9. ... (Was deprecated in NumPy 1.16.) (gh-17900) ... Raises ValueError if low > high...
Read more >NumPy 1.16.6 Release Notes
The NumPy 1.16.6 release fixes bugs reported against the 1.16.5 release, and also backports several enhancements from master that seem appropriate for a ......
Read more >NumPy 1.15.0 Release Notes
NumPy 1.16 will drop support for Python 3.4. ... and the exceptions for non-square matrices have been changed to LinAlgError (from ValueError )....
Read more >NumPy 1.20.0 Release Notes
For example, the following used to incorrectly give ValueError: operands could ... The fix is to either compile against 1.16.6 (if the NumPy...
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
Yes, it works with Cython 0.28.3 and numpy 1.16.0.dev0+2804c03.
My apologies. You are totally right. I managed to reproduce the error with python 3.6, cython master and numpy 1.14.5. I’m going to investigate and see if an earlier version of cython or numpy does the trick.