What's the difference of numpy.ndarray.T and numpy.ndarray.transpose() when self.ndim < 2
The document numpy.ndarray.T s开发者_高级运维ays
ndarray.T — Same as self.transpose(), except that self is returned if self.ndim < 2.
Also, ndarray.transpose(*axes) says
For a 1-D array, this has no effect.
Doesn't this mean the same thing?
Here's a little demo snippet:
>>> import numpy as np
>>> print np.__version__
1.5.1rc1
>>> a = np.arange(7)
>>> print a, a.T, a.transpose()
[0 1 2 3 4 5 6] [0 1 2 3 4 5 6] [0 1 2 3 4 5 6]
Regardless of rank, the .T
attribute and the .transpose()
method are the same—they both return the transpose of the array.
In the case of a rank 1 array, the .T
and .transpose()
don't do anything—they both return the array.
It looks like .T
is just a convenient notation, and that .transpose(*axes)
is the more general function and is intended to give more flexibility, as axes can be specified. They are apparently not implemented in Python, so one would have to look into C code to check this.
精彩评论