The following for everyone to share a numpy in the implementation of a two-dimensional array in accordance with a column, a row of the method, has a good reference value, I hope to be helpful to everyone. Come and see it together.
How do I sort by a row in a two-dimensional array or a column? Suppose that data is a two-dimensional array of type Numpy.array, which can be implemented using the Argsort function in NumPy, with the following code example:
data = Data[data[:,2].argsort ()] #按照第3列对行排序
Note: Argsort returns only the sorted row index and does not change the original array.
To sort by a row, you can take advantage of the transpose operation, as shown in the code below:
data = data. T (data. T[:,2].argsort ()). T # Sort Columns According to line 3rd
You can also sort directly by line, with the following code:
data = Data[:,data[2].argsort ()]