This is a pre-release version (2.5.0.dev0+git20251130.2de293a). Go to latest (2.4.4)
{ } Raw JSON

bundles / numpy 2.5.0.dev0+git20251130.2de293a / numpy / place

_ArrayFunctionDispatcher

numpy:place

source: /dev/numpy/build-install/usr/lib/python3.14/site-packages/numpy/lib/_function_base_impl.py :2100

Signature

def   place ( arr mask vals )

Summary

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

Extended Summary

Similar to np.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.

Note that extract does the exact opposite of place.

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 in mask. If vals is smaller than N, it will be repeated, and if elements of a 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

See also

copyto
extract
put
take

Aliases

  • numpy.place