Python Forum

Full Version: "erlarge" a numpy-matrix to numpy-array
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi all!

Is there a way to concatenate/append/"gluetogether" two (n*m-shaped) matrix into a single (n*m*2-shaped) array (with 3 axle), and not into an other (2n*m-shaped) or (n*2m-shaped) matrix?

I found a couple of websites about putting matrixes together, but these sites were about how to do it row~ or column~wise.
So, you have two matrices of shape nxm and want to concatenate them by third axis and get one matrix of shape nxmx2.
Thats easy:
import numpy as np
A = np.random.rand(10, 20)
B = np.random.rand(10, 20)
C = np.dstack([A, B])
print(C.shape)
Thank you!

This is exactly, what I want.