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.
Answers:
np.where(diff > np.average(diff))[0]
?
output:
array([1, 2, 3, 4, 5, 7])
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.
np.where(diff > np.average(diff))[0]
?
output:
array([1, 2, 3, 4, 5, 7])