This is a story about converting a row vector to a column vector with python's ndarray.
Involuntarily, it's easy to do the following.
print(np.array([1,2,3,4,5]).T)
But with this, the result is
[1 2 3 4 5]
And cannot be converted to a row vector.
This is because the row vector is represented by a one-dimensional array.
This is because a column vector can only be represented by an array of two or more dimensions.
In fact,
print(np.array([[1,2,3,4,5]]).T)
If you pass a row vector in a two-dimensional array like
[[1]
[2]
[3]
[4]
[5]]
I get the result.
By the way
print(np.transpose(np.array([1,2,3,4,5])))
The same is true for, and the column vector cannot be obtained.
If you want to get the column vector m
(as a two-dimensional array) from the row vector v
as a one-dimensional array,
m = np.array([v]).T
Let's say
Recommended Posts