排序
numpy.sort( )
numpy.sort(a[, axis=-1, kind=‘quicksort’, order=None]) Return a sorted copy of an array.
axis:排序沿数组的(轴)方向,0表示按列,1表示按行,None表示展开来排序,默认为-1,表示沿最后的轴排序。
kind:排序的算法,提供了快排’quicksort’、混排’mergesort’、堆排’heapsort’, 默认为‘quicksort’。
order:排序的字段名,可指定字段排序,默认为None。
【例】
import numpy as np
np.random.seed(20200612)
x = np.random.rand(5, 5) * 10
x = np.around(x, 2)
[[2.32 7.54 9.78 1.73 6.22]
[6.93 5.17 9.28 9.76 8.25]
[0.01 4.23 0.19 1.73 9.27]
[7.99 4.97 0.88 7.32 4.29]
[9.05 0.07 8.95 7.9 6.99]]
y = np.sort(x)
y = np.sort(x, axis=1)
[[1.73 2.32 6.22 7.54 9.78]
[5.17 6.93 8.25 9.28 9.76]
[0.01 0.19 1.73 4.23 9.27]
[0.88 4.29 4.97 7.32 7.99]
[0.07 6.99 7.9 8.95 9.05]]
y = np.sort(x, axis=0)
[[0.01 0.07 0.19 1.73 4.29]