Reputation: 1222
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, but X.fft.fft
fails.
Thanks all!
Upvotes: 5
Views: 20297
Reputation: 541
X.T
means transpose of X.
For example lets say this is our X:
X.T is going to be:
Upvotes: 2
Reputation: 405925
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.
Upvotes: 5