📜  Python| numpy matrix.sort()

📅  最后修改于: 2022-05-13 01:54:27.388000             🧑  作者: Mango

Python| numpy matrix.sort()

matrix.sort()方法的帮助下,我们可以使用相同的方法对矩阵中的值进行排序。

示例 #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]]