Sorting Numpy Arrays

The numpy.sort() function is used in Numpy to sort arrays in a sequence. This sequence can be ascending or descending. Here, we will see how to,

  • Sort a One-Dimensional Integer Array
  • Sort a One-Dimensional String Array
  • Sort a Two-Dimensional Array

Sort a 1D Numpy Integer array

We will create an array in Numpy with integer elements using the numpy.array() method. To sort it, the numpy.sort() method will be used. Let us see an example:

Output

Sort a 1D Numpy string array

We will create an array in Numpy with string elements using the numpy.array() method. To sort it, the numpy.sort() method will be used. Let us see an example:

Output

Sort a 2D array

A 2D array gets sorted individually using the sort() function. Let us see an example:

Output

If you liked the tutorial, spread the word and share the link and our website Studyopedia with others.

For Videos, Join Our YouTube Channel: Join Now


Read More:

Search a Numpy Array for a value
Axes in Numpy arrays
Studyopedia Editorial Staff
Studyopedia Editorial Staff
[email protected]

We work to create programming tutorials for all.

No Comments

Post A Comment

Discover more from Studyopedia

Subscribe now to keep reading and get access to the full archive.

Continue reading