Issue
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]]
Solution
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])
Answered By - user1740577
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.