【发布时间】:2017-02-01 17:28:39
【问题描述】:
我根据几个条件创建了一个索引
transition = np.where((rain>0) & (snow>0) & (graup>0) & (xlat<53.) & (xlat>49.) & (xlon<-114.) & (xlon>-127.)) #indexes the grids where there are transitions
形状为 (3,259711),如下所示:
array([[ 0, 0, 0, ..., 47, 47, 47], #hour
[847, 847, 848, ..., 950, 950, 951], #lat gridpoint
[231, 237, 231, ..., 200, 201, 198]]) #lon gridpoint
我还有其他几个变量(例如 temp),其形状为 (48, 1015, 1359),对应于小时、纬度、经度。
鉴于索引是我的有效网格点,我如何屏蔽所有变量,如 temp 以便它保留 (48,1015,1359) 形状,但屏蔽索引之外的值。
【问题讨论】:
-
mask到底是什么意思?对于什么样的操作?对于某些东西,掩码数组 (np.ma) 子类可能很有用。 -
感谢您的建议。我已经尝试过使用 numpy.ma.masked_where(idx, temp),但是我的形状 IndexError: Inconsistant shape between the condition and the input (got (3, 259711) and (48, 1015, 1359)) @ hpaulj
-
masked_where想要隐藏值的布尔掩码,而不是where生成的索引元组。产生这个where元组的条件矩阵是什么? -
@hpaulj 嗯,嗯,好吧,有没有办法使用索引(使用 np.where),这样那些索引就不会被屏蔽,而其余的被屏蔽?