What does X.T in Python do?
13,397
Solution 1
The numpy.array
function returns an ndarray
object, so when you call
X = np.array([[1,2,3],[4,5,6]])
the variable X
is assigned an ndarray
. That object has a T
method, which transposes the array.
Calling T
like the following:
np.T(X)
doesn't work because the numpy library doesn't have a free-floating function named T
that takes an array as an argument, just the method in the ndarray
class.
Solution 2
X.T
means transpose of X.
For example lets say this is our X:
X.T is going to be:
Author by
Doubt
Updated on June 04, 2022Comments
-
Doubt almost 2 years
I am very new to Python. I am using the transpose operator in the numpy package:
>>> import numpy as np >>> X = np.array([[1,2,3],[4,5,6]]) >>> np.T(X) Traceback (most recent call last): File "<pyshell#8>", line 1, in <module> np.T(X) AttributeError: 'module' object has no attribute 'T'
Why is it that this is an error, yet
X.T
works? Furthermore,X.np.T
fails. On the other hand,np.fft.fft(X)
succeeds, butX.fft.fft
fails.Thanks all!