1

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 1

3

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]),)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.