Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Numpy
import numpy as np
## 1. sort()
## Sorting along flattened array
a = np.array([[5,4],[3,1]])
np.sort(a)
#[Output]:
#array([[4, 5],
# [1, 3]])
## Sorting along first axis i.e, columns(down)
np.sort(a,axis=0)
#[Output]:
#array([[3, 1],
# [5, 4]])
## 2. argsort()
np.argsort(a.flatten())
#[Output]:
#array([3, 2, 1, 0], dtype=int64)
## Sorting along first axis
np.argsort(a,axis=0)
#[Output]:
#array([[1, 1],
# [0, 0]], dtype=int64)
## Sorting along last axis
np.argsort(a,axis=1)
#[Output]:
#array([[1, 0],
# [1, 0]], dtype=int64)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.