我想掩盖一些数组的值.阵列是3D,掩模是2D.
我想掩饰所有的coordonates方向frametemperature_reshape.shape[0].
我尝试了以下循环:
for i in range(frametemperature_reshape.shape[0]):
frames_BPnegl = np.ma.array(frametemperature_reshape[i,:,:], mask=mask2)
Run Code Online (Sandbox Code Playgroud)
您可以针对3D阵列广播 2D蒙版,以便沿第3维扩展其大小,而不会在内存中实际复制它:
import numpy as np
x = np.random.randn(10, 20, 30)
mask = np.random.randn(10, 20) > 0
# broadcast `mask` along the 3rd dimension to make it the same shape as `x`
_, mask_b = np.broadcast_arrays(x, mask[..., None])
xm = np.ma.masked_array(x, mask_b)
Run Code Online (Sandbox Code Playgroud)