python – How to append numpy arrays?

python – How to append numpy arrays?

One way would be to use np.vstack on 3D extended versions of those arrays –

np.vstack((A[None],B[None]))

Another way with np.row_stack (functionally same as np.vstack) –

np.row_stack((A[None],B[None]))

And similarly with np.concatenate

np.concatenate((A[None],B[None])) # By default stacks along axis=0

Another way would be with np.stack and specifying the axis of stacking i.e. axis=0 or skip it as thats the default axis of stacking –

np.stack((A,B))

python – How to append numpy arrays?

Leave a Reply

Your email address will not be published.