Adjust Values In Numpy Array Based On Coefficients
I'm using a threshold vector to create binary values in a 2d numpy array row-wise. Sample code is provided below: import numpy as np x = np.random.rand(100000, 200) coef = np.rando
Solution 1:
Perform the comparison with coef
to give us a boolean array and then convert to int
array, thus leveraging vectorized capabilities of NumPy -
x_out = (x >= coef).astype(int)
Post a Comment for "Adjust Values In Numpy Array Based On Coefficients"