Numpy mask based on if a value is in some other list

后端 未结 2 1620
心在旅途
心在旅途 2021-01-17 10:42

I have searched high and low and just cant find a way to do it (Its possible i was searching for the wrong terms.)

I would like to create a mask (eg [True False Fal

相关标签:
2条回答
  • 2021-01-17 11:13

    Accepted answer is right but currently numpy's docs recommend using isin function instead of in1d

    0 讨论(0)
  • 2021-01-17 11:25

    Use numpy.in1d():

    In [6]: np.in1d(a, [14, 16, 18])
    Out[6]: array([False, False, False,  True, False,  True, False], dtype=bool)
    
    0 讨论(0)
提交回复
热议问题