Phoenix
Phoenix

Reputation: 399

concatenate numpy 1D array in columns

I have two numpy arrays:

a = np.array([1, 2, 3])
b = np.array([4, 5, 6])

and I want to concatenate them into two columns like,

1 4
2 5
3 6 

is there any way to do this without transposing or reshaping the arrays?

Upvotes: 0

Views: 117

Answers (1)

Startiflette
Startiflette

Reputation: 111

You can try:

a = np.array([1, 2, 3])
b = np.array([4, 5, 6])
c = np.concatenate((a[np.newaxis, :], b[np.newaxis, :]), axis = 0).T

And you get :

c = array([[1, 4], [2, 5], [3, 6]])

Best,

Upvotes: 1

Related Questions