Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Python3中按升序对二维数组列进行排序,按降序对行进行排序_Python_Python 3.x_Numpy - Fatal编程技术网

如何在Python3中按升序对二维数组列进行排序,按降序对行进行排序

如何在Python3中按升序对二维数组列进行排序,按降序对行进行排序,python,python-3.x,numpy,Python,Python 3.x,Numpy,这是我的阵列: import numpy as np boo = np.array([ [10, 55, 12], [0, 81, 33], [92, 11, 3] ]) 如果我打印: [[10 55 12] [ 0 81 33] [92 11 3]] 如何按升序排列数组列,按降序排列行,如下所示: [[33 81 92] [10 12 55] [0 3 11]] # import the necessary packages. import nump

这是我的阵列:

import numpy as np
boo = np.array([
    [10, 55, 12],
    [0, 81, 33],
    [92, 11, 3]
])
如果我打印:

[[10 55 12]
 [ 0 81 33]
 [92 11  3]]
如何按升序排列数组列,按降序排列行,如下所示:

[[33 81 92]
 [10 12 55]
  [0 3  11]]
# import the necessary packages.
import numpy as np

# create the array.
boo = np.array([
    [10, 55, 12],
    [0, 81, 33],
    [92, 11, 3]
])

# we use numpy's 'sort' method to conduct the sorting process.
# we first sort the array along the rows.
boo = np.sort(boo, axis=0)

# we print to observe results.
print(boo)

# we therafter sort the resultant array again, this time on the axis of 1/columns.
boo = np.sort(boo, axis=1)

# we thereafter reverse the contents of the array.
print(boo[::-1])

# output shows as follows:
array([[33, 81, 92],
       [10, 12, 55],
       [ 0,  3, 11]])