🔥Limited Offer: Get 50% OFFon AI & Full Stack Courses🔥
Back to NumPy Notes
Topic #15

NumPy Array Sort


Sorting Arrays

Sorting means putting elements in an ordered sequence.

Ordered sequence is any sequence that has an order corresponding to elements, like numeric or alphabetical, ascending or descending.

The NumPy ndarray object has a function called sort(), that will sort a specified array.

Example

  import numpy as np

  arr = np.array([3, 2, 0, 1])

print(np.sort(arr))

Note: This method returns a copy of the array, leaving the original array unchanged.

You can also sort arrays of strings, or any other data type:

Example

  import numpy as np

  arr = np.array(['banana', 'cherry', 'apple'])

print(np.sort(arr))

Example

  import numpy as np

  arr = np.array([True, False, True])

print(np.sort(arr))

Sorting a 2-D Array

If you use the sort() method on a 2-D array, both arrays will be sorted:

Example

  import numpy as np

arr = np.array([[3, 2, 4], [5, 0, 1]])

print(np.sort(arr))

Want to go beyond the notes?

Join CodingNow 2.0's NumPy course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

NumPy Array Sort – FAQs

Quick answers about learning NumPy Array Sort in NumPy.

This free note from CodingNow 2.0 explains NumPy Array Sort in NumPy — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every NumPy topic on CodingNow 2.0, including NumPy Array Sort, is 100% free with no signup required.
With focused practice, most students grasp NumPy Array Sort in 1–3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) — expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now