I create a masked array A with shape (8,1,51,120) and a data masked array B with shape (11232,51,120).
Now I make a loop to select bar of B[step,:,:] array and append it at the end of A[foo,0,:,:]. Here is some pseudo-code to describe what I want:
for step in range(B.shape[0]):
foo = select_func(step)
A[foo,A.shape[1]-1,:,:].append(B[step,:,:])
print(A[foo,:,:,:].shape)
Finally I want A[foo,:,:,:].shape = (bar,51,120).
It turns out very hard to append B to A using np.ma.dstack( or np.ma.append( not only because A not change as I do but also it made new masked array.
I try this: Append 2D array to 3D array, extending third dimension, but I want my original A array grow up not to make new array.
numpyyou can't 'grow up' an array. You can only make a new array with values copied from the originals. Arrays are not the same lists in this regard. And the 'joining' functions (np.concatenateand the 'stack' relatives) all require some degree of shape compatibility.