You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
NPY201 can produce broken code. Replacing numpy.sometrue with any is dangerous and does not work for multidimensional arrays. Using numpy.any instead is probably a better option.
numpy 1.26.4:
>>> import numpy as np
>>> a = np.array([[False, False], [False, False]])
>>> np.sometrue(a)
False
>>> np.any(a)
False
>>> any(a)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
numpy 2.0:
>>> import numpy as np
>>> a = np.array([[False, False], [False, False]])
>>> np.any(a)
np.False_
>>> any(a)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
Probably the same for numpy.alltrue.
The text was updated successfully, but these errors were encountered:
radoering
changed the title
NPY201: replacing sometrue/alltrue with any/all results in invalid code
NPY201: replacing sometrue/alltrue with any/all results in broken code
Jul 20, 2024
NPY201 can produce broken code. Replacing
numpy.sometrue
withany
is dangerous and does not work for multidimensional arrays. Usingnumpy.any
instead is probably a better option.numpy 1.26.4:
numpy 2.0:
Probably the same for
numpy.alltrue
.The text was updated successfully, but these errors were encountered: