2

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]

2 Answers 2

2

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].

Sign up to request clarification or add additional context in comments.

Comments

2

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

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.