↧
Answer by Mateen Ulhaq for How to filter a numpy array using a condition in...
v = v[v > 1]indices = np.argpartition(v, -3)[-3:]values = v[indices]As mentioned here, argpartition runs in O(n + k log k) time. In your case, n = 1e6, k=3.
View ArticleHow to filter a numpy array using a condition in python
I am using my numpy array v as follows to remove elements that are <=1 and then select the indexes of the top 3 elements in the numpy array. for ele in v.toarray()[0].tolist(): if ele <= 1:...
View Article
More Pages to Explore .....