如何在python中使用条件过滤numpy数组

如何在python中使用条件过滤numpy数组,python,numpy,Python,Numpy,我使用我的numpyarray v来删除 如前所述,argpartition在+k log k时间运行。在你的例子中,n=1e6,k=3。你的缩进有点奇怪,那么v[v>1]呢?@MateenUlhaq编辑了这个问题。 for ele in v.toarray()[0].tolist(): if ele <= 1: useless_index = v.toarray()[0].tolist().index(ele) temp_

我使用我的numpyarray v来删除
如前所述,argpartition在+k log k时间运行。在你的例子中,n=1e6,k=3。

你的缩进有点奇怪,那么v[v>1]呢?@MateenUlhaq编辑了这个问题。
 for ele in v.toarray()[0].tolist():
        if ele <= 1:
            useless_index = v.toarray()[0].tolist().index(ele)
            temp_list.append(useless_index)

 #take top 3 words from each document
 indexes =v.toarray()[0].argsort()[-3:]
 useful_list = list(set(indexes) - set(temp_list))
v = v[v > 1]
indices = np.argpartition(v, -3)[-3:]
values = v[indices]