Sorting, Searching, and Counting

cupy.argmax(a, axis=None, dtype=None, out=None, keepdims=False)[source]

Returns the indices of the maximum along an axis.

Parameters:
  • a (cupy.ndarray) – Array to take argmax.
  • axis (int) – Along which axis to find the maximum. a is flattened by default.
  • dtype – Data type specifier.
  • out (cupy.ndarray) – Output array.
  • keepdims (bool) – If True, the axis axis is preserved as an axis of length one.
Returns:

The indices of the maximum of a along an axis.

Return type:

cupy.ndarray

See also

numpy.argmax()

cupy.argmin(a, axis=None, dtype=None, out=None, keepdims=False)[source]

Returns the indices of the minimum along an axis.

Parameters:
  • a (cupy.ndarray) – Array to take argmin.
  • axis (int) – Along which axis to find the minimum. a is flattened by default.
  • dtype – Data type specifier.
  • out (cupy.ndarray) – Output array.
  • keepdims (bool) – If True, the axis axis is preserved as an axis of length one.
Returns:

The indices of the minimum of a along an axis.

Return type:

cupy.ndarray

See also

numpy.argmin()

cupy.count_nonzero(x)[source]

Counts the number of non-zero values in the array.

Parameters:x (cupy.ndarray) – The array for which to count non-zeros.
Returns:Number of non-zero values in the array.
Return type:int
cupy.nonzero(a)[source]

Return the indices of the elements that are non-zero.

Returns a tuple of arrays, one for each dimension of a, containing the indices of the non-zero elements in that dimension.

Parameters:a (cupy.ndarray) – array
Returns:Indices of elements that are non-zero.
Return type:tuple of arrays

See also

numpy.nonzero()

cupy.flatnonzero(a)[source]

Return indices that are non-zero in the flattened version of a.

This is equivalent to a.ravel().nonzero()[0].

Parameters:a (cupy.ndarray) – input array
Returns:Output array, containing the indices of the elements of a.ravel() that are non-zero.
Return type:cupy.ndarray
cupy.where(condition, x=None, y=None)[source]

Return elements, either from x or y, depending on condition.

If only condition is given, return condition.nonzero().

Parameters:
  • condition (cupy.ndarray) – When True, take x, otherwise take y.
  • x (cupy.ndarray) – Values from which to choose on True.
  • y (cupy.ndarray) – Values from which to choose on False.
Returns:

Each element of output contains elements of x when condition is True, otherwise elements of y. If only condition is given, return the tuple condition.nonzero(), the indices where condition is True.

Return type:

cupy.ndarray

See also

numpy.where()