numpy基础——matrix.transpose() 和 matrix.getA()

来源:互联网 发布:易语言 网页源码 编辑:程序博客网 时间:2024/05/21 22:45

numpy.matrix.getA

matrix.getA()[source]

返回一个数组对象

Return self as an ndarray object.

Equivalent to np.asarray(self).

Parameters: None
Returns: ret : ndarray
self as an ndarray

Examples

>>> x = np.matrix(np.arange(12).reshape((3,4))); xmatrix([[ 0,  1,  2,  3],        [ 4,  5,  6,  7],        [ 8,  9, 10, 11]])>>> x.getA()array([[ 0,  1,  2,  3],       [ 4,  5,  6,  7],       [ 8,  9, 10, 11]])

numpy.matrix.transpose

矩阵转置

Returns a view of the array with axes transposed.

For a 1-D array, this has no effect. (To change between column and row vectors, first cast the 1-D array into a matrix object.) For a 2-D array, this is the usual matrix transpose. For an n-D array, if axes are given, their order indicates how the axes are permuted (see Examples). If axes are not provided and a.shape = (i[0], i[1], … i[n-2], i[n-1]), then a.transpose().shape = (i[n-1], i[n-2], … i[1], i[0]).

Examples

>>> a = np.array([[1, 2], [3, 4]])>>> aarray([[1, 2],       [3, 4]])>>> a.transpose()array([[1, 3],       [2, 4]])>>> a.transpose((1, 0))array([[1, 3],       [2, 4]])>>> a.transpose(1, 0)array([[1, 3],       [2, 4]])
原创粉丝点击