How do I access and modify Python arrays using boolean operators?
I would like to know how to execute the following MATLAB statement in Python:
X(0.80 < X & X < 1) = 1;
The statement says Put 1 in the indices where the value of X is between 0.8 and 1
.
I'm looking for a solution in NumPy arrays of Python lists.
Thank.
I tried:
X[X > 0.8 and X < 1]
but he says: ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
+3
source to share