Home > Enterprise >  How to convert result of np.where to array?
How to convert result of np.where to array?

Time:11-27

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.

CodePudding user response:

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

output:

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

  • Related