-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
bugSomething isn't workingSomething isn't workingfixesRelated to suggested fixes for violationsRelated to suggested fixes for violations
Description
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.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingfixesRelated to suggested fixes for violationsRelated to suggested fixes for violations