For example, I have a array with value [1,2,4,3,6,7,33,2]. I want to get all the values which are bigger than 6. As I know the numpy.take can only get values with indices.
Which function should I use?
1 Answer
You can index into the array with a boolean array index:
>>> a = np.array([1,2,4,3,6,7,33,2])
>>> a > 6
array([False, False, False, False, False, True, True, False], dtype=bool)
>>> a[a > 6]
array([ 7, 33])
If you want the indices where this occurs, you can use np.where:
>>> np.where(a>6)
(array([5, 6]),)