Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

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])
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #numpy #replace #values
ADD COMMENT
Topic
Name
2+9 =