-
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 thatplace
uses the first N elements ofvals
, where N is the number of True values inmask
, whilecopyto
uses the elements wheremask
is True.Note that
extract
does the exact opposite ofplace
.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
. Ifvals
is smaller than N it will be repeated.Examples
12345>>> arr
=
np.arange(
6
).reshape(
2
,
3
)
>>> np.place(arr, arr>
2
, [
44
,
55
])
>>> arr
array([[
0
,
1
,
2
],
[
44
,
55
,
44
]])
numpy.place()

2025-01-10 15:47:30
Please login to continue.