Python 3.x Python3矩阵求和

Python 3.x Python3矩阵求和,python-3.x,numpy,Python 3.x,Numpy,您好,我已经创建了代码,我想知道是否可以按总和对列进行排序,使其更小并向右增长 import numpy as np a = np.random.randint(100, size=(4,4)) a = list(a) print(a) b = sum(a) print(b) 输出: Matrix [[26 11 39 81] [55 82 20 81] [ 7 42 28 26] [69 50 24 86]] Secnd THird FRST

您好,我已经创建了代码,我想知道是否可以按总和对列进行排序,使其更小并向右增长

import numpy as np
a = np.random.randint(100, size=(4,4))
a = list(a)
print(a)
b = sum(a)
print(b)
输出:

    Matrix
    [[26 11 39 81]
    [55 82 20 81]
    [ 7 42 28 26]
    [69 50 24 86]]
   Secnd  THird  FRST  RD
    Sum
    [157 185 111 274]
   Secnd  THird  FRST  RD

我想让它像

你可以尝试以下方法:

a=np.random.randint(100,大小=(4,4)) >>>a 数组([[38,51,49,6], [81, 16, 84, 75], [76, 83, 13, 92], [99, 76, 8, 91]]) >>>a.总和(轴=0) 数组([294226154264])
# get the sort indices
>>> idx = np.argsort(a.sum(axis=0))

# copy the array based on the sorted indices
>>> b = np.copy(a[:,idx])

>>> b.sum(axis=0)
array([154, 226, 264, 294])