The .T
attribute returns the array transpose. Note that in your case, you declared almost a vector (a real vector would be one dimensional, but in your case you have two dimensions because of the double brackets [[]]
use in the definition of x):
import numpy as np
x = np.array([[147, 150, 153, 158, 163, 165, 168, 170, 173, 175, 178, 180]])
print("Line vector:")
print(x)
print("Column vector:")
print(x.T)
Line vector:
[[147 150 153 158 163 165 168 170 173 175 178 180]]
Column vector:
[[147]
[150]
[153]
[158]
[163]
[165]
[168]
[170]
[173]
[175]
[178]
[180]]
Note that in this case, there is no need to use double square brackets [[]]
. If you define x
with single brackets, the transpose is not different (because there is no dimension to transpose with):
import numpy as np
x = np.array([147, 150, 153, 158, 163, 165, 168, 170, 173, 175, 178, 180])
print("Line vector:")
print(x)
print("Column vector:")
print(x.T)
Line vector:
[147 150 153 158 163 165 168 170 173 175 178 180]
Column vector:
[147 150 153 158 163 165 168 170 173 175 178 180]