Issue
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!
Solution
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.
Answered By - Bill the Lizard
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.