Np.transpose Doesn't Return Transpose Of Matrix
When I write my code in the following manner : from numpy import * H = array([1,1]) Ht = transpose(H) Ht I get the same matrix as H instead of the transpose of H. But when I chang
Solution 1:
From the documentation:
numpy.matrix.transpose. Returns a view of the array with axes transposed. For a 1-D array, this has no effect. (To change between column and row vectors, first cast the 1-D array into a matrix object.)
Solution 2:
I think this is the behavior you're looking for:
>>> H = np.array([[1,1]])
>>> H.T
array([[1],
[1]])
Equivalently you can write np.transpose(H)
. Notice this array has shape (1,2)
, so it has two dimensions. The array H = np.array([1,2])
has shape (2,)
. It only has one dimension. To swap the dimensions (transpose), you need at least two of them.
Post a Comment for "Np.transpose Doesn't Return Transpose Of Matrix"