Searching Functions ¶
Array API specification for functions for searching arrays.
A conforming implementation of the array API standard must provide and support the following functions adhering to the following conventions.

Positional parameters must be positionalonly parameters. Positionalonly parameters have no externallyusable name. When a function accepting positionalonly parameters is called, positional arguments are mapped to these parameters based solely on their order.

Optional parameters must be keywordonly arguments.

Broadcasting semantics must follow the semantics defined in Broadcasting .

Unless stated otherwise, functions must support the data types defined in Data Types .

Unless stated otherwise, functions must adhere to the type promotion rules defined in Type Promotion Rules .
Objects in API ¶
argmax(x, /, *, axis=None, keepdims=False) ¶
Returns the indices of the maximum values along a specified axis. When the maximum value occurs multiple times, only the indices corresponding to the first occurrence are returned.
Parameters ¶

x : <array>

input array.


axis : Optional[ int ]

axis along which to search. If
None
, the function must return the index of the maximum value of the flattened array. Default:None
.


keepdims : bool

If
True
, the reduced axes (dimensions) must be included in the result as singleton dimensions, and, accordingly, the result must be compatible with the input array (see Broadcasting ). Otherwise, ifFalse
, the reduced axes (dimensions) must not be included in the result. Default:False
.

Returns ¶

out : <array>

if
axis
isNone
, a zerodimensional array containing the index of the first occurrence of the maximum value; otherwise, a nonzerodimensional array containing the indices of the maximum values. The returned array must have be the default array index data type.

argmin(x, /, *, axis=None, keepdims=False) ¶
Returns the indices of the minimum values along a specified axis. When the minimum value occurs multiple times, only the indices corresponding to the first occurrence are returned.
Parameters ¶

x : <array>

input array.


axis : Optional[ int ]

axis along which to search. If
None
, the function must return the index of the minimum value of the flattened array. Default:None
.


keepdims : bool

If
True
, the reduced axes (dimensions) must be included in the result as singleton dimensions, and, accordingly, the result must be compatible with the input array (see Broadcasting ). Otherwise, ifFalse
, the reduced axes (dimensions) must not be included in the result. Default:False
.

Returns ¶

out : <array>

if
axis
isNone
, a zerodimensional array containing the index of the first occurrence of the minimum value; otherwise, a nonzerodimensional array containing the indices of the minimum values. The returned array must have the default array index data type.

nonzero(x, /) ¶
Datadependent output shape
The shape of the output array for this function depends on the data values in the input array; hence, array libraries which build computation graphs (e.g., JAX, Dask, etc.) may find this function difficult to implement without knowing array values. Accordingly, such libraries may choose to omit this function. See Datadependent output shapes section for more details.
Returns the indices of the array elements which are nonzero.
Parameters ¶

x : <array>

input array. Must have a positive rank. If
x
is zerodimensional, the function must raise an exception.

Returns ¶

out : Tuple[ <array>, … ]

a tuple of
k
arrays, one for each dimension ofx
and each of sizen
(wheren
is the total number of nonzero elements), containing the indices of the nonzero elements in that dimension. The indices must be returned in rowmajor, Cstyle order. The returned array must have the default array index data type.

where(condition, x1, x2, /) ¶
Returns elements chosen from
x1
or
x2
depending on
condition
.
Parameters ¶

condition : <array>

when
True
, yieldx1_i
; otherwise, yieldx2_i
. Must be compatible withx1
andx2
(see Broadcasting ).


x1 : <array>

first input array. Must be compatible with
condition
andx2
(see Broadcasting ).


x2 : <array>

second input array. Must be compatible with
condition
andx1
(see Broadcasting ).

Returns ¶

out : <array>

an array with elements from
x1
wherecondition
isTrue
, and elements fromx2
elsewhere. The returned array must have a data type determined by Type Promotion Rules rules with the arraysx1
andx2
.
