Search
 
SCRIPT & CODE EXAMPLE
 

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])
Comment

PREVIOUS NEXT
Code Example
Python :: bst deleting in python 
Python :: how to loop through every character in a string 
Python :: python 3 documentation 
Python :: Return array of odd rows and even columns from array using numpy 
Python :: histogram relative frequency 
Python :: python order list by multiple index 
Python :: python get global variable by name 
Python :: add button to python gui file 
Python :: get all permutations of string 
Python :: how to stop python for certain time in python 
Python :: python string [::-1] 
Python :: numpy percentile 
Python :: django table view sort filter 
Python :: sum() python 
Python :: how to store something in python 
Python :: argparse parse path 
Python :: python inspect.getsource 
Python :: tensorflow use growing memory 
Python :: python list of dict change dicts id by position in list when moved 
Python :: gpu DBSCAN python 
Python :: avoid bad request django 
Python :: python unpack list 
Python :: pandas convert hex string to int 
Python :: convert timestamp to period pandas 
Python :: union type python 
Python :: import tkinter module in python file 
Python :: python selenium: does not wait until page is loaded after a click() command 
Python :: how to make python script run forever 
Python :: python cheat 
Python :: add element to array list python 
ADD CONTENT
Topic
Content
Source link
Name
8+4 =