Tutorial on np.where
Example: np.where
import numpy as np
X = np.array(
[[ 0.4, 1.2, -0.6],
[ 1.6, -0.9, 0.5],
[-0.4, -1.4, 1.7]]
)
Z = np.where(X < 0, 0, X)
print(Z)
- Example 2: Determining Predicted Classes
We can us np.where
to blah blah blah.
Example: np.where
import numpy as np
np.set_printoptions(suppress=True, precision=2)
np.random.seed(1)
prob = np.random.uniform(low=0, high=1, size=8)
pred = np.where(prob < 0.5, 'A', 'B')
print('prob =', prob, '\n')
print('pred =', pred)