How to convert result of np.where to array?

Question:

I have an array from which I want to get the indices of the elements of interest by condition np.where:

diff = [19, 403472, 403491, 403491, 403491, 403491, 13, 403478, 13]
np.where(diff > np.average(diff))

As result I have tuple:

(array([1, 2, 3, 4, 5, 7], dtype=int64),)

But I want only array:

array([1, 2, 3, 4, 5, 7]

And list() don’t help.

Can you please help? Thanks.

Asked By: catauggie

||

Answers:

np.where(diff > np.average(diff))[0]?

output:

array([1, 2, 3, 4, 5, 7])

Answered By: JayPeerachai
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.