如何在多列上屏蔽 numpy 结构化数组?
我有一个带有 dtype 的 numpy 结构化数组,例如:
A = numpy.empty(10, dtype=([('segment', '<i8'), ('material', '<i8'), ('rxN', '<i8')]))
我知道我可以创建一个掩码,例如:
A[A['segment'] == 42] = ...
有没有办法在多列上创建掩码?例如(我知道这不起作用,但我希望它能起作用):
A[A['segment'] == 42 and A['material'] == 5] = ...
I have a numpy structured array with a dtype such as:
A = numpy.empty(10, dtype=([('segment', '<i8'), ('material', '<i8'), ('rxN', '<i8')]))
I know I can create a mask such as:
A[A['segment'] == 42] = ...
Is there a way to create a mask on multiple columns? For example (I know this doesn't work, but I wish it did):
A[A['segment'] == 42 and A['material'] == 5] = ...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
&
运算符代替and
:请注意,需要额外的括号。
You can use the
&
operator instead ofand
:Note that extra parantheses are required.