user1220022
user1220022

Reputation: 12105

Combining an array using Python and NumPy

I have two arrays of the form:

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

Is there a NumPy function which I can apply to these arrays to get the followng output?

[[1,4],[2,5][3,6]]

Upvotes: 2

Views: 1964

Answers (1)

eumiro
eumiro

Reputation: 213085

np.vstack((a,b)).T

returns

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

and

np.vstack((a,b)).T.tolist()

returns exactly what you need:

[[1, 4], [2, 5], [3, 6]]

Upvotes: 7

Related Questions