Note
Numpy (47) 본문
728x90
How to replace all values greater than a given value to a given cutoff?
# Input
np.set_printoptions(precision=2)
np.random.seed(100)
a = np.random.uniform(1,50, 20)
# 1: Using np.clip
np.clip(a, a_min=10, a_max=30)
# 2: Using np.where
print(np.where(a < 10, 10, np.where(a > 30, 30, a)))
# output
[ 27.63 14.64 21.8 30. 10. 10. 30. 30. 10. 29.18 30.
11.25 10.08 10. 11.77 30. 30. 10. 30. 14.43]
'Numpy' 카테고리의 다른 글
Numpy (49) (0) | 2022.09.15 |
---|---|
Numpy (48) (0) | 2022.09.14 |
Numpy (46) (0) | 2022.09.12 |
Numpy (45) (0) | 2022.09.11 |
Numpy (44) (0) | 2022.09.10 |
Comments