Ravi Vishwakarma is a dedicated Software Developer with a passion for crafting efficient and innovative solutions. With a keen eye for detail and years of experience, he excels in developing robust software systems that meet client needs. His expertise spans across multiple programming languages and technologies, making him a valuable asset in any software development project.
ICSM Computer
18-Nov-20251. Basic Sorting
Output:
2. Sorting a 2D Array
By default, NumPy sorts rows individually.
Output:
3. Sorting by Axis
Sort each column
Sort each row
4. Using
np.argsort()(Get Sorted Indices)argsort()returns indices of sorted elements.Output:
You can use it to rearrange the array:
5. Sorting Structured Arrays (Sort by Field)
6. In-place Sorting
You can sort an array without creating a copy:
7. Sorting in Descending Order
NumPy does not have a direct parameter like
reverse=True,but you can reverse after sorting:
Summary
np.sort()arr.sort()np.argsort()np.sort(arr, axis=0/1)np.sort(order='field')