bundles / numpy 2.4.3 / numpy / put
_ArrayFunctionDispatcher
numpy:put
source: /numpy/_core/fromnumeric.py :488
Signature
def put ( a , ind , v , mode = raise ) Summary
Replaces specified elements of an array with given values.
Extended Summary
The indexing works on the flattened target array. put is roughly equivalent to:
a.flat[ind] = vParameters
a: ndarrayTarget array.
ind: array_likeTarget indices, interpreted as integers.
v: array_likeValues to place in
aat target indices. Ifvis shorter thanindit will be repeated as necessary.mode: {'raise', 'wrap', 'clip'}, optionalSpecifies how out-of-bounds indices will behave.
'raise' -- raise an error (default)
'wrap' -- wrap around
'clip' -- clip to the range
'clip' mode means that all indices that are too large are replaced by the index that addresses the last element along that axis. Note that this disables indexing with negative numbers. In 'raise' mode, if an exception occurs the target array may still be modified.
Examples
import numpy as np a = np.arange(5) np.put(a, [0, 2], [-44, -55]) a✓
a = np.arange(5) np.put(a, 22, -5, mode='clip') a✓
See also
- place
- put_along_axis
Put elements by matching the array and the index arrays
- putmask
Aliases
-
numpy.put