Python| numpy matrix.sort()
在matrix.sort()
方法的帮助下,我们可以使用相同的方法对矩阵中的值进行排序。
Syntax : matrix.sort()
Return : Return a sorted matrix
示例 #1:
在这个例子中,我们可以使用matrix.sort()
方法对矩阵中的元素进行排序。
# import the important module in python
import numpy as np
# make matrix with numpy
gfg = np.matrix('[4, 1; 12, 3]')
# applying matrix.sort() method
gfg.sort()
print(gfg)
输出:
[[ 1 4]
[ 3 12]]
示例 #2:
# import the important module in python
import numpy as np
# make matrix with numpy
gfg = np.matrix('[4, 1, 9; 12, 3, 1; 4, 5, 6]')
# applying matrix.sort() method
gfg.sort()
print(gfg)
输出:
[[ 1 4 9]
[ 1 3 12]
[ 4 5 6]]