Numpy开关从列编号到行

Han*_*nah 1 python numpy

我需要改变矩阵的编号方案.说,

import numpy as np
a = np.arange(6).reshape(3,2)
array([[0, 1],
       [2, 3],
       [4, 5]])
Run Code Online (Sandbox Code Playgroud)

我想把它切换到

b = np.array([[0,3],[1,4],[2,5]])
array([[0, 3],
       [1, 4],
       [2, 5]])
Run Code Online (Sandbox Code Playgroud)

所以基本上我首先通过行对矩阵进行编号.我相信在numpy中有一个很好的方法可以做到这一点

Joh*_*nal 5

>>> import numpy as np
>>> np.arange(6).reshape(3,2, order = 'F')
>>> array([[0, 3],
   [1, 4],
   [2, 5]])
Run Code Online (Sandbox Code Playgroud)

来自doc:

http://docs.scipy.org/doc/numpy/reference/generated/numpy.reshape.html

使用order ='F'指定Fortran传统表示,并使用order ='C'(默认值)来使用传统的C表示.