简体   繁体   English

当self.ndim <2时,numpy.ndarray.T和numpy.ndarray.transpose()的区别是什么?

[英]What's the difference of numpy.ndarray.T and numpy.ndarray.transpose() when self.ndim < 2

The document numpy.ndarray.T says 文件numpy.ndarray.T

ndarray.T — Same as self.transpose(), except that self is returned if self.ndim < 2. ndarray.T - 与self.transpose()相同,只是如果self.ndim <2则返回self。

Also, ndarray.transpose(*axes) says 另外,ndarray.transpose(* axes)说

For a 1-D array, this has no effect. 对于1-D阵列,这没有任何影响。

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. 无论等级如何, .T属性和.transpose()方法都是相同的 - 它们都返回数组的转置。

In the case of a rank 1 array, the .T and .transpose() don't do anything—they both return the array. 在排名为1的数组中, .T.transpose()不执行任何操作 - 它们都返回数组。

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. 看起来.T只是一个方便的符号,而.transpose(*axes)是更通用的功能,旨在提供更大的灵活性,因为可以指定轴。 They are apparently not implemented in Python, so one would have to look into C code to check this. 它们显然没有在Python中实现,因此需要查看C代码来检查它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM