开发者

How to mask numpy structured array on multiple columns?

开发者 https://www.devze.com 2023-03-22 12:10 出处:网络
I have a numpy structured array with a dtype such as: A = numpy.empty(10, dtype=([(\'segment\', \'<i8\'), (\'material\', \'<i8\'), (\'rxN\', \'<i8\')]))

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 t开发者_Go百科his doesn't work, but I wish it did):

A[A['segment'] == 42 and A['material'] == 5] = ...


You can use the & operator instead of and:

A[(A['segment'] == 42) & (A['material'] == 5)]

Note that extra parantheses are required.

0

精彩评论

暂无评论...
验证码 换一张
取 消