Without a loop, you can write it as:
field3d_mask[:,:,:] = field2d[np.newaxis,:,:] > 0.3
For instance:
field3d_mask_1 = np.zeros(field3d.shape, dtype=bool) field3d_mask_2 = np.zeros(field3d.shape, dtype=bool) for t in range(nt): field3d_mask_1[t,:,:] = field2d > 0.3 field3d_mask_2[:,:,:] = field2d[np.newaxis,:,:] > 0.3 print((field3d_mask_1 == field3d_mask_2).all())
gives:
True
source share