Skip to content

Instantly share code, notes, and snippets.

@hughdbrown
Created August 20, 2015 19:39
Show Gist options
  • Save hughdbrown/c306af3bcc14c40e6043 to your computer and use it in GitHub Desktop.
Save hughdbrown/c306af3bcc14c40e6043 to your computer and use it in GitHub Desktop.
Useful fragments of numpy code

Selection

where

>>> import numpy as np
>>> a = np.array([[7, 4, 3, 7],
...  [7, 2, 5, 4],
...  [1, 7, 5, 1]])
>>> for (i, j) in zip(*np.where(a % 2 == 0)):
...     print("[{0}, {1}]: {2}".format(i, j, a[i, j]))
... 
[0, 1]: 4
[1, 1]: 2
[1, 3]: 4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment