# credit to Stack Overflow user in the source link
import numpy as np
arr = np.array([100, 10, 500, 400, 1, 20]) # define your array
th, val = 200, 0
cond = arr > th # in general, a boolean expression is required
arr[cond] = x
print(arr)
>>> array([100, 10, 0, 0, 1, 20])