Skip to content

Instantly share code, notes, and snippets.

@Robofied
Created February 15, 2019 15:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Robofied/64ad049d50b79808698eb27711ede37d to your computer and use it in GitHub Desktop.
Save Robofied/64ad049d50b79808698eb27711ede37d to your computer and use it in GitHub Desktop.
Numpy
import numpy as np
## 1. argmax()
a = np.arange(6).reshape(2,3)
print(a)
#[Output]:
#[[0 1 2]
# [3 4 5]]
## argsort() for flattened array
print(np.argmax(a))
#[Output]:
#5
## agrsort() along first axis
print(np.argmax(a, axis=0))
#[Output]:
#array([1, 1, 1], dtype=int64)
## 2. argwhere()
## It is returning the indices of elements which are satisfying the condition.
print(np.argwhere(a>=2))
#[Output]:
#array([[0, 2],
# [1, 0],
# [1, 1],
# [1, 2]], dtype=int64)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment