Note
Numpy (5) 본문
How to replace items that satisfy a condition with another value in numpy array?
arr = np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
Output
array([ 0, -1, 2, -1, 4, -1, 6, -1, 8, -1])
# input
arr[arr % 2 == 1] = -1
arr
# output
array([ 0, -1, 2, -1, 4, -1, 6, -1, 8, -1])
728x90