Getting only those values that fulfill a condition in a numpy array

前端 未结 3 675
北恋
北恋 2021-01-01 10:33

There must a be a (very) quick and efficient way to get only elements from a numpy array, or even more interestingly from a slice of it. Suppose I have a numpy array:

<
3条回答
  •  不思量自难忘°
    2021-01-01 10:49

    I'm aware that this is an old question, and I'm not sure if the following was available at the time it was asked, but since I got here with a similar question, this is what I found that worked for me:

    np.extract(a[s] > 0, a[s])
    

提交回复
热议问题