1

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.

3
  • have you checked this? stackoverflow.com/questions/34357617/… Commented Jan 15, 2022 at 17:11
  • I checked it. It can't broadcast results to the original array the way I want Commented Jan 15, 2022 at 17:25
  • 4
    In numpy you 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.concatenate and the 'stack' relatives) all require some degree of shape compatibility. Commented Jan 15, 2022 at 17:35

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.