Home > Software engineering >  Concatenate a matrix 5x2 and 5x3
Concatenate a matrix 5x2 and 5x3

Time:03-10

I have two arrays A1(5,3) and A2(5,2) and want to create a new array A(5,5). I've try to use A=np.concatenate((A1,A2)) but it gives me the error

all the input array dimensions for the concatenation axis must match exactly, but along dimension 1, the array at index 0 has size 3 and the array at index 1 has size 2

How can I solve this?

CodePudding user response:

To use np.concatenate you should specify on which axis the concatenation is happening. In this case, you should use:

A = np.concatenate((A1, A2), axis=1)

Other way to solve this issue is to use horizontal stack:

A = np.hstack((A1, A2))
  • Related