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 by slices to a. If all of the indices target different locations, the operation of scatter_max() is equivalent to a[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 of a, the initial element of a 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 to numpy.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__() and cupy.ndarray.__setitem__().

  • v (array-like) – An array used for reference.