I want to create a 3d mask from a 2d mask. Lets assume I have a 2d mask like:
mask2d = np.array([[ True, True ,False],
[ True , True, False],
[ True , True ,False]])
mask3d = np.zeros((3,3,3),dtype=bool)
The desired output should look like:
mask3d = [[[ True True False]
[ True True False]
[ True True False]]
[[ True True False]
[ True True False]
[ True True False]]
[[ True True False]
[ True True False]
[ True True False]]]
Now I want to create a 3d array mask with the 2d array mask in every z slice. It should work no matter how big the 3d array is in z direction How would i do this?
EDIT
Ok now I try to find out, which method is faster. I know I could to it with timepit, but I do not realyunderstand why in the first method he loops 10000 times and in the second 1000 times:
mask3d=np.zeros((3,3,3),dtype=bool)
def makemask():
b = np.zeros(mask3d,dtype=bool)
b[:]=mask2d
%timeit for x in range(100): np.repeat(mask[np.newaxis,:], 4, 0)
%timeit for x in range(100): makemask()