[Numpy] numpy.transpose () transposition function

【官网】https://docs.scipy.org/doc/numpy-1.15.0/reference/generated/numpy.transpose.html

numpy.transpose(a, axes=None)[source]

Parameters a: array_like, the input array.

Parameters axes: int list, alternatively, by default, reverse dimensions, as arranged according to a given value of coordinate axes.
Examples
>>> x = np.arange(4).reshape((2,2))
>>> x
array([[0, 1],
       [2, 3]])
>>> np.transpose(x)
array([[0, 2],
       [1, 3]])
>>> x = np.ones((1, 2, 3))
>>> np.transpose(x, (1, 0, 2)).shape
(2, 1, 3)

1, transpose the array can be reset, returning the source data is a view (not proceed any copying operation)

2, transposed in three ways:

    (1) transpose Method
    (2) T Properties
    (3) swapaxes method.

T applies to a two-dimensional array

>>> Import numpy AS NP
 >>> ARR = np.arange (20 is) .reshape (4,5) # generates an array of four rows and five columns 
>>> ARR 
Array ([[0,   . 1, 2,. 3, . 4 ], 
       [ . 5,. 6,. 7,. 8,. 9 ], 
       [ 10,. 11, 12 is, 13 is, 14 ], 
       [ 15, 16,. 17, 18 is,. 19 ]])
 >>> arr.T  # seek transpose 
Array ([[0,. 5, 10, 15 ], 
       [ . 1,. 6,. 11, 16 ], 
       [ 2,. 7, 12 is,. 17 ], 
       [ . 3,. 8, 13 is, 18 is ], 
       [ . 4,. 9, 14, 19]])

https://www.cnblogs.com/sunshinewang/p/6893503.html

Guess you like

Origin www.cnblogs.com/ITCSJ/p/11314953.html