根据值是否在其他列表中而生成的numpy蒙版 [英] Numpy mask based on if a value is in some other list

查看:76
本文介绍了根据值是否在其他列表中而生成的numpy蒙版的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经搜索了高低档,却找不到解决方法(可能是我搜索了错误的字词.)

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

我想根据每个值是否在其他列表中来创建掩码(例如[True False False True True True]).

I would like to create a mask (eg [True False False True True]) based on whether each value is in some other list.

a=np.array([11,12,13,14,15,16,17])
mask= a in [14,16,8] #(this doesnt work at all!)
#I would like to see [False False False True False True False]

到目前为止,我能提出的最好的建议是列表理解

so far the best i can come up with is a list comprehension

mask = [True if x in other_list else False for x in my_numpy_array]

请让我知道您是否知道一些秘密的调味料可以快速地(以计算方式)执行此操作,因为实际上这个列表很大...

please let me know if you know of some secret sauce to do this with numpy and fast (Computationally), as this list in reality is huge...

推荐答案

使用 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆