Edit: Question updated - I should have asked:
Why is this:
new_x = x[(0<x<10) & (20<x<40)]
giving me "ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()"?
The original question I posted did not reflect the problem I was having (apologies - my actual conditions are more complicated and I had oversimplified it). Original question below:
I have a numpy array x and I want to create a new array of x elements satisfying x>0 and x<10. I have tried all the following:
new_x = x[(x>0) and (x<10)] new_x = x[(x>0) & (x<10)] new_x = x[np.logical_and(x>0, x<10)] new_x = x[np.where(x>0, x<10)] new_x = x[np.all(x>0, x<10)] new_x = x[np.all((x>0) and (x<10))] new_x = x[np.all(x>0) and np.all(x<10)] new_x = x[np.any(x>0, x<10)]
and they all give the following error:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
I have ran out of ideas. I realise this may be a duplicate question but I have consulted this and this and many others which did not help as I keep getting the same value error.
Edit: Fixed typo (x<0 and x>10) --> (x>0 and x<10)