查找在 Numpy 中被屏蔽的位置

Find where is masked in Numpy

我想获取掩码数组中的位置。 像这样

wt[chl > 10] = 3
wt[(chl < 10) & (chl > 5)] = 2
wt[(chl < 5)] = 1
wt[(chl is masked )]=0

wt 和 chl 形状相同。我想根据chl的值和属性(是否屏蔽)给wt值。

有人知道我该怎么做吗?

提前致谢。

argwhere returns 值非零的索引,因此如果形状相等,

wt[np.argwhere(chi)] = 0

应将 wt 归零,其中 chi 为非零(并且 ~np.argwhere(chi) 将索引归零,其中 chi 零)。

您可以直接访问 chlmask 属性并将其用作索引:

wt[chl.mask] = 0