Skip to main content

where

Return elements chosen from x or y depending on a condition. When called with only a condition, returns the indices of non-zero elements (equivalent to nonzero).
Returns: NDArray when x and y are given (array of chosen elements). NDArray[] when only condition is given (tuple of index arrays, one per dimension).

nonzero

Return the indices of non-zero elements. For an N-dimensional array, returns a tuple of N arrays, one for each dimension.
Returns: NDArray[] — Tuple of arrays, one per dimension, containing the indices of non-zero elements.

argwhere

Find the indices of non-zero elements, returned as a 2D array where each row is the index tuple of a non-zero element.
Returns: NDArray — 2D array of shape (N, a.ndim) where N is the number of non-zero elements. Each row is the multi-dimensional index of a non-zero element.

flatnonzero

Return indices of non-zero elements in the flattened version of the array.
Returns: NDArray — 1D array of indices into the flattened array where elements are non-zero.

searchsorted

Find indices where elements should be inserted to maintain sorted order. The input array a must be sorted in ascending order.
Returns: NDArray — Indices of insertion points.

extract

Return elements of an array where a condition is true. Equivalent to a[condition] on the flattened array.
Returns: NDArray — 1D array of elements from a where condition is true.

count_nonzero

Count the number of non-zero elements in the array.
Returns: number when no axis is specified. NDArray when counting along specific axes.