
NumPy transpose - How to make the transpose of a matrix or vector
T or transpose method of NumPy array returns the transpose of a matrix.
import numpy
a = numpy.array([[1, 2], [3, 4]])
b = a.T
c = a.transpose()
print(a.T)
'''
[[1 3]
[2 4]]
'''
print(c)
'''
[[1 3]
[2 4]]
'''
a.T is the transpose of a.
Transpose of vector
T and transpose don't work for vector.
import numpy
a = numpy.array([1, 2])
b = a.T
c = a.transpose()
print(a.T)
'''
[1 2]
'''
print(c)
'''
[1 2]
'''
Nothing changes. But if you change numpy.array([1, 2])
to numpy.array([[1, 2]])
, both methods work.
import numpy
a = numpy.array([[1, 2]])
b = a.T
c = a.transpose()
print(a.T)
'''
[[1]
[2]]
'''
print(c)
'''
[[1]
[2]]
'''
Comments
Powered by Markdown