flopscope.numpy.place
fnp.place(arr, mask, vals, *args, **kwargs)[flopscope source][numpy source]
Change elements of an array based on conditional and input values.
Adapted from NumPy docs np.place
Cost
4×per-operation
Flopscope Context
Change elements satisfying condition. Cost: numel(input).
Similar to flops.copyto(arr, vals, where=mask), the difference is that
place uses the first N elements of vals, where N is the number of
True values in mask, while copyto uses the elements where mask
is True.
Parameters
- arr:ndarray
Array to put data into.
- mask:array_like
Boolean mask array. Must have the same size as
a.- vals:1-D sequence
Values to put into
a. Only the first N elements are used, where N is the number of True values inmask. Ifvalsis smaller than N, it will be repeated, and if elements ofaare to be masked, this sequence must be non-empty.
See also
Examples
>>> import flopscope.numpy as fnp
>>> arr = flops.arange(6).reshape(2, 3)
>>> flops.place(arr, arr>2, [44, 55])
>>> arr
array([[ 0, 1, 2],
[44, 55, 44]])