我正在寻找一种方法,使用.where来掩盖3D数组中的数据,这样,如果第二维和第三维内的任何值都为true,它将返回整个第二维和第三维矩阵,而不是仅返回那些是真的。
我将xarray用于包含200多个变量的数据集。这些变量中的许多都是多维数组。一个阵列特别地具有110×16×6的形状。我想屏蔽我的数据集,以便如果16x6值中的任何一个都超过某个数字,则返回该索引处的整个16x6矩阵。
我尝试将.where与drop = True结合使用,但它会沿数据数组的所有3个维度返回所有假值。我只希望在整个16x6矩阵都没有我要查找的值的情况下删除值。
In: DS.cloud_layer_top_level_height.shape
Out: (110, 16, 6)
In: DS.cloud_layer_top_level_height[0]
Out: <xarray.DataArray 'cloud_layer_top_level_height' (Cloud groups: 16,
Cloud
Layers: 6)>
array([[2.801278, nan, nan, nan, nan, nan],
[3.37 , nan, nan, nan, nan, nan],
[2.861235, nan, nan, nan, nan, nan],
[2.981151, nan, nan, nan, nan, nan],
[2.981151, nan, nan, nan, nan, nan],
[2.711341, nan, nan, nan, nan, nan],
[2.861235, nan, nan, nan, nan, nan],
[2.801278, nan, nan, nan, nan, nan],
[2.981151, nan, nan, nan, nan, nan],
[2.981151, nan, nan, nan, nan, nan],
[2.711341, nan, nan, nan, nan, nan],
[2.711341, nan, nan, nan, nan, nan],
[2.711341, 1.362293, nan, nan, nan, nan],
[2.711341, 1.272357, nan, nan, nan, nan],
[2.681362, nan, nan, nan, nan, nan],
[2.681362, nan, nan, nan, nan, nan]],
dtype=float32)
Dimensions without coordinates: Cloud groups, Cloud Layers
Attributes:
units: kilometers
format: F18.9
valid_range: [-0.5 30. ]
In: DS=DS.where(DS.cloud_layer_top_level_height>3,drop=True)
Out: DS.cloud_layer_top_level_height[0]
<xarray.DataArray 'cloud_layer_top_level_height' (Cloud groups: 16, Cloud
Layers: 4)>
array([[ nan, nan, nan, nan],
[3.37, nan, nan, nan],
[ nan, nan, nan, nan],
[ nan, nan, nan, nan],
[ nan, nan, nan, nan],
[ nan, nan, nan, nan],
[ nan, nan, nan, nan],
[ nan, nan, nan, nan],
[ nan, nan, nan, nan],
[ nan, nan, nan, nan],
[ nan, nan, nan, nan],
[ nan, nan, nan, nan],
[ nan, nan, nan, nan],
[ nan, nan, nan, nan],
[ nan, nan, nan, nan],
[ nan, nan, nan, nan]], dtype=float32)
Dimensions without coordinates: Cloud groups, Cloud Layers
Attributes:
units: kilometers
format: F18.9
valid_range: [-0.5 30. ]
理想情况下,由于该第一个索引包含一个大于3的值,所以我希望返回该矩阵内的所有值,而不是仅返回大于3的单个值。而且,如果第一个维度索引不包含大于3的值大于3(在16x6矩阵中),我希望将其删除。