Gregory Price
Gregory Price

Reputation: 89

Is there a simple function to change the values rows of an array to columns in another array?

Okay, I have an array that has 5 rows and one column. I have another array with 5 columns, and 1 row. Is there a way that I can change the values of the array with the rows to the columns in a simpler way. I know that I can do this:

 import numpy as np
 x = np.ones(5)
 y = np.zeros([5,1])
 y[:,0] = x

Is there a easier way of doing this. I will be flipping many values in rows to columns, and this may get messy in my actual code.

Upvotes: 0

Views: 87

Answers (1)

Adrien Matissart
Adrien Matissart

Reputation: 1690

You are looking for reshape.

y = x.reshape((5,1))

Upvotes: 3

Related Questions