cupyx.scatter_max#
- cupyx.scatter_max(a, slices, value)[source]#
Stores a maximum value of elements specified by indices to an array.
It stores the maximum value of elements in
value
array indexed byslices
toa
. If all of the indices target different locations, the operation ofscatter_max()
is equivalent toa[slices] = cupy.maximum(a[slices], value)
. If there are multiple elements targeting the same location,scatter_max()
stores the maximum of all of these values to the given index ofa
, the initial element ofa
is also taken in account.Note that just like an array indexing, negative indices are interpreted as counting from the end of an array.
Also note that
scatter_max()
behaves identically tonumpy.maximum.at()
.Example
>>> import numpy >>> import cupy >>> a = cupy.zeros((6,), dtype=numpy.float32) >>> i = cupy.array([1, 0, 1, 2]) >>> v = cupy.array([1., 2., 3., -1.]) >>> cupyx.scatter_max(a, i, v); >>> a array([2., 3., 0., 0., 0., 0.], dtype=float32)
- Parameters:
a (ndarray) – An array to store the results.
slices – It is integer, slices, ellipsis, numpy.newaxis, integer array-like, boolean array-like or tuple of them. It works for slices used for
cupy.ndarray.__getitem__()
andcupy.ndarray.__setitem__()
.v (array-like) – An array used for reference.