Reputation: 49
What i have done so far is Sort out the Top 3 position of values of an array, but i am looking out to get the only values which are more than 0.20..... in Descending order.
label = np.array(genres)
print(label)
#OUTPUT: [0.1892372 0.29031774 0.19473006 0.01859367 0.10489976 0.20222157]
label = label.argsort()[::-1][:3]
Output i am getting is :
Output:
[1 5 2]
Output looking for :
label = [0.29031774 0.20222157]
[1 5]
Upvotes: 2
Views: 1100
Reputation: 390
pls attach this
labelargs = label.argsort()[::-1][:3]
print(labelargs) ## this will print [1 5 2]
labelargs = [x for x in labelargs if label[x]>0.2]
print(labelargs) ## this will print [1 5]
regards
Upvotes: 2
Reputation: 221504
Get those specific indices and then index -
# Get all valid indices
In [12]: idx = np.flatnonzero(label>0.2)
# Index into input array and get descending order
In [20]: idx[np.argsort(label[idx])[::-1]]
Out[20]: array([1, 5])
Variations of np.flatnonzero()
, would be np.nonzero()[0]
and np.where()[0]
.
Upvotes: 2