self.ndim<时,numpy.ndarray.T和numpy.ndarray.transpose()有什么区别? 2个 [英] What's the difference of numpy.ndarray.T and numpy.ndarray.transpose() when self.ndim < 2
本文介绍了self.ndim<时,numpy.ndarray.T和numpy.ndarray.transpose()有什么区别? 2个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
文档 numpy. ndarray.T 说
ndarray.T —与self.transpose()相同,不同之处在于,如果self.ndim< 2.
ndarray.T — Same as self.transpose(), except that self is returned if self.ndim < 2.
此外,ndarray.transpose(* axes)表示
Also, ndarray.transpose(*axes) says
对于一维数组,这无效.
For a 1-D array, this has no effect.
这不是同一回事吗?
下面是一些演示代码段:
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]
推荐答案
不管排名如何,.T
属性和.transpose()
方法都是相同的-它们都返回数组的转置.
Regardless of rank, the .T
attribute and the .transpose()
method are the same—they both return the transpose of the array.
对于秩为1的数组,.T
和.transpose()
不执行任何操作-它们都返回数组.
In the case of a rank 1 array, the .T
and .transpose()
don't do anything—they both return the array.
这篇关于self.ndim<时,numpy.ndarray.T和numpy.ndarray.transpose()有什么区别? 2个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文