while using .T command on a 2d or a 3d matrix it works very well but when it is applied on a 1D matrix then we don’t get our matrix transposed. can you tell me the reason.
A 1D array in numpy would be of shape (n,) whereas if we decode this shape, we can say that it will be a row vector.
The transpose of a row vector in mathematical context will be a column vector. A column vector would be having the shape (n, 1). Which in context of numpy would become a 2D array.
So, we cannot just take transpose of 1D arrays, but you can use np.ravel() to convert any given array to (n,1) shape.
Thanks for the answer
let say we have c=[1,2,3]
how to take transpose of c
If it’s a list, then you might first need to convert it into a 1D numpy array. For this you can do
And then apply the above explained rule to transpose it.
The second option is to directly convert the given list into a 2D array, and then take it’s transpose. Example:
Note that the square braces are responsible for transforming 1D list to a 2D numpy array.