简体   繁体   English

使用子掩码掩码 numpy 阵列

[英]Mask numpy array with a submask

I am trying to figure out an elegant way to make a combined mask between two arrays of different size with numpy , but that the mask of one corresponds to the elements of the mask that have passed the large mask.我试图找出一种优雅的方法来在两个不同大小的 arrays 与numpy之间制作组合掩码,但是其中一个掩码对应于通过大掩码的掩码元素。 To understand this well I put an example:为了更好地理解这一点,我举了一个例子:

We have two mask arrays (understanding that 1 is True and 0 is False):我们有两个掩码 arrays(理解为 1 为真,0 为假):

a = [0,1,1,1,0,1]
b = [0,0,1,0]

With b being the 4 elements corresponding to the 1s of a, so the result of this should be: b 是对应于 a 的 1 的 4 个元素,所以结果应该是:

c = [0,0,0,1,0,0]

I keep thinking that there must be some native numpy operation that I must be missing or something, so I'd appreciate some help with this.我一直在想,一定有一些本机 numpy 操作我必须丢失或其他什么,所以我很感激一些帮助。

This works:这有效:

a = np.array([0,1,1,1,0,1])
b = np.array([0,0,1,0])

c = a.copy()
c[c == True] = b

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM