Answers for "numpy replace all values with another"

0

numpy replace all values with another

# 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])
Posted by: Guest on May-03-2022

Code answers related to "numpy replace all values with another"

Python Answers by Framework

Browse Popular Code Answers by Language