numpy.place#

numpy.place(arr,mask,vals)[source]#

Change elements of an array based on conditional and input values.

Similar tonp.copyto(arr,vals,where=mask), the difference is thatplace uses the first N elements ofvals, where N is the number ofTrue values inmask, whilecopyto uses the elements wheremaskis True.

Note thatextract does the exact opposite ofplace.

Parameters:
arrndarray

Array to put data into.

maskarray_like

Boolean mask array. Must have the same size asa.

vals1-D sequence

Values to put intoa. Only the first N elements are used, whereN is the number of True values inmask. Ifvals is smallerthan N, it will be repeated, and if elements ofa are to be masked,this sequence must be non-empty.

Examples

>>>importnumpyasnp>>>arr=np.arange(6).reshape(2,3)>>>np.place(arr,arr>2,[44,55])>>>arrarray([[ 0,  1,  2],       [44, 55, 44]])
On this page