I have an numpy array in Python and i need to classify between a range of value (>= 2 to < 5 = 100). I got an error message and I don't understand the use of a.any() or a.all()
import numpy as np
myarray = np.array([[1,2,3,4,5],[1,2,3,4,5],[1,2,3,4,5]])
myarray[myarray >= 2 and myarray < 5] = 100
Traceback (most recent call last):
File "<input>", line 1, in <module>
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
__array_interface__ A dictionary of items (3 required and 5 optional). The optional keys in the dictionary have implied defaults if they are not provided. The keys are: shape (required) Tuple whose elements are the array size in each dimension.
values returns a numpy array with the underlying data of the DataFrame, without any index or columns names.
You were so close.
>>> myarray[(myarray >= 2) & (myarray < 5)] = 100
>>> myarray
array([[ 1, 100, 100, 100, 5],
[ 1, 100, 100, 100, 5],
[ 1, 100, 100, 100, 5]])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With