numpy.putmask
- 
numpy.putmask(a, mask, values) - 
Changes elements of an array based on conditional and input values.
Sets
a.flat[n] = values[n]for each n wheremask.flat[n]==True.If
valuesis not the same size asaandmaskthen it will repeat. This gives behavior different froma[mask] = values.- Parameters
 - 
- 
aarray_like - 
Target array.
 - 
maskarray_like - 
Boolean mask array. It has to be the same shape as
a. - 
valuesarray_like - 
Values to put into
awheremaskis True. Ifvaluesis smaller thanait will be repeated. 
 - 
 
Examples
>>> x = np.arange(6).reshape(2, 3) >>> np.putmask(x, x>2, x**2) >>> x array([[ 0, 1, 2], [ 9, 16, 25]])If
valuesis smaller thanait is repeated:>>> x = np.arange(5) >>> np.putmask(x, x>1, [-33, -44]) >>> x array([ 0, 1, -33, -44, -33])
 
    © 2005–2020 NumPy Developers
Licensed under the 3-clause BSD License.
    https://numpy.org/doc/1.18/reference/generated/numpy.putmask.html