Home > Web Front-end > JS Tutorial > body text

Numpy operates two-dimensional arrays sorted by rows and columns

php中世界最好的语言
Release: 2018-04-09 17:15:11
Original
2437 people have browsed it

This time I will bring you numpy operationsTwo-dimensional arraysSort by rows and columns, numpy operates two-dimensional arrays by rows and rowsWhat are the precautionsWhat are the practical cases? Get up and take a look.

How to sort according to a certain row or column in a two-dimensional array? Assume that data is a two-dimensional array of type numpy.array, which can be implemented using the argsort function in numpy. The code example is as follows:

data = data[data[:,2].argsort()] #按照第3列对行排序
Copy after login

Note: argsort returns only the sorted rows index and will not change the original array. To sort according to a certain row, you can use the transpose operation.

The code is as follows:

data = data.T(data.T[:,2].argsort()).T # 按照第3行对列进行排序
Copy after login
Also Sort directly by row,

The code is as follows:

data = data[:,data[2].argsort()]
Copy after login
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the PHP Chinese website !

Recommended reading:

How to perform automated unit testing with Python Unittest


Python operates excel to read and write data

The above is the detailed content of Numpy operates two-dimensional arrays sorted by rows and columns. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!