numpy.place#
- numpy.place(arr, mask, vals)[source]#
Change elements of an array based on conditional and input values.
Similar to
np.copyto(arr, vals, where=mask), the difference is thatplaceuses the first N elements of vals, where N is the number of True values in mask, whilecopytouses the elements where mask is True.Note that
extractdoes the exact opposite ofplace.- Parameters:
- arrndarray
Array to put data into.
- maskarray_like
Boolean mask array. Must have the same size as arr.
- vals1-D sequence
Values to put into arr. Only the first N elements are used, where N is the number of True values in mask. If vals is smaller than N, it will be repeated, and if elements of arr are to be masked, this sequence must be non-empty.
Examples
>>> import numpy as np >>> arr = np.arange(6).reshape(2, 3) >>> np.place(arr, arr>2, [44, 55]) >>> arr array([[ 0, 1, 2], [44, 55, 44]])