numpy.msort
numpy.msort(a) [source]
返回沿第一个轴排序的数组的副本。
参数 : | a :array_like 要排序的数组。 |
返回值 : | s或ted_array :ndarray 与类型和形状相同的数组。 |
Notes
np.msort(a)
等效于np.sort(a,axis = 0)
。
1)一维数组排序
import numpy as np a = np.array([3, 1, 2]) sorted_a = np.msort(a) print(sorted_a)
2)二维数组按最后一个轴(即行内)排序
import numpy as np a = np.array([[3, 2, 1], [6, 5, 4]]) sorted_a = np.msort(a) print(sorted_a)
3)三维数组排序(按最后一个轴)
import numpy as np a = np.array([[[2, 1], [4, 3]], [[6, 5], [8, 7]]]) sorted_a = np.msort(a) print(sorted_a)