[SOLVED] How to use multiple conditional expressions to select values from a NUMPY array?


This Content is from Stack Overflow. Question asked by zo Aoo

b = np.array([2,3,4,5])

we can get the values which are greater than 1 in b.


b = np.array([2,3,4,5])
b[b>=1 and b <= 2] 

will raise ValueError.

How can i fix this problem?


b = np.array([2,3,4,5])
b[(b>=1) & ( b <= 2)] 

This Question was asked in StackOverflow by zo Aoo and Answered by Shishu Kumar Choudhary It is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?