where
Return elements chosen fromx or y depending on a condition. When called with only a condition, returns the indices of non-zero elements (equivalent to nonzero).
| Name | Type | Default | Description |
|---|---|---|---|
condition | ArrayLike | — | Boolean or numeric array. Where true (non-zero), yield x; otherwise yield y. |
x | ArrayLike | undefined | Values where condition is true. Required if y is provided. |
y | ArrayLike | undefined | Values where condition is false. Required if x is provided. |
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.| Name | Type | Default | Description |
|---|---|---|---|
a | ArrayLike | — | Input array. |
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.| Name | Type | Default | Description |
|---|---|---|---|
a | ArrayLike | — | Input array. |
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.| Name | Type | Default | Description |
|---|---|---|---|
a | ArrayLike | — | Input array. |
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 arraya must be sorted in ascending order.
| Name | Type | Default | Description |
|---|---|---|---|
a | ArrayLike | — | Sorted 1D input array. |
v | ArrayLike | — | Values to insert. |
side | 'left' | 'right' | 'left' | If 'left', the index of the first suitable location is returned. If 'right', the last suitable location is returned. |
NDArray — Indices of insertion points.
extract
Return elements of an array where a condition istrue. Equivalent to a[condition] on the flattened array.
| Name | Type | Default | Description |
|---|---|---|---|
condition | ArrayLike | — | Boolean array. Must be broadcastable to the shape of a. |
a | ArrayLike | — | Input array. |
NDArray — 1D array of elements from a where condition is true.
count_nonzero
Count the number of non-zero elements in the array.| Name | Type | Default | Description |
|---|---|---|---|
a | ArrayLike | — | Input array. |
axis | number | undefined | Axis along which to count. If undefined, counts over the entire array. |
number when no axis is specified. NDArray when counting along specific axes.