Numpy np.where
np.where
seems to be an important function that need to
be noticed.
Two examples to show its function.
np.where(condition, x, y)
1
2
3
4
5
6
7import numpy as np
1,2,3]) x = np.mat([
x
matrix([[1, 2, 3]])
1, 0, x) y = np.where(x >
y
array([[1, 0, 0]])np.where(condition)
1
2
3
4
5
6
7import numpy as np
1,2,3]) x = np.mat([
x
matrix([[1, 2, 3]])
1) y = np.where(x >
y
(array([0, 0]), array([1, 2]))