0

I am new to python and numpy. I am trying to convert a 1D array into a column , I used transpose, but not working, please any help, I attached the code:

import numpy as np
x=np.array([1,2,3])
print(x)
y=x.T
print(y)
#output should be:
#y=[[1],
 #   [2],
#    [3]]

1 Answers1

1

You can use transpose for 2d array and you can see difference for your output you can use .reshape(-1,1) like below:

>>> x.reshape(-1,1)
array([[1],
       [2],
       [3]])

Or You can read with more detail in this thread and try this:

>>> np.array([x]).T

>>> np.transpose([x])
I'mahdi
  • 23,382
  • 5
  • 22
  • 30