python api numpy where

less than 1 minute read

stackoverflow example

import numpy as np

x = np.arange(9).reshape(3,3)
print (x > 5)
[[False False False]
 [False False False]
 [ True  True  True]]


x = np.arange(9.).reshape(3, 3)
x
Out[3]:
array([[0., 1., 2.],
       [3., 4., 5.],
       [6., 7., 8.]])


out = np.where( x > 5 )
out
Out[5]:
(array([2, 2, 2]), array([0, 1, 2]))