Created
February 15, 2019 18:10
-
-
Save Robofied/6a7021cc7c0869e064d3359968658a73 to your computer and use it in GitHub Desktop.
Numpy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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