diag_indices
Return the indices to access the main diagonal of an array withndim dimensions.
| Name | Type | Default | Description |
|---|---|---|---|
n | number | — | Size of the array along each dimension. |
ndim | number | 2 | Number of dimensions. |
NDArray[] — Tuple of ndim index arrays, each of length n, that together select the main diagonal.
diag_indices_from
Return the indices to access the main diagonal of a given array.| Name | Type | Default | Description |
|---|---|---|---|
a | ArrayLike | — | Array whose diagonal indices are desired. Must be at least 2-D and have equal-length dimensions. |
NDArray[] — Tuple of index arrays that select the main diagonal of arr.
tril_indices
Return the indices for the lower triangle of an (n, m) array.| Name | Type | Default | Description |
|---|---|---|---|
n | number | — | Number of rows in the array. |
k | number | 0 | Diagonal offset. k=0 is the main diagonal, k<0 is below it, k>0 is above it. |
m | number | n | Number of columns. Defaults to n (square array). |
[NDArray, NDArray] — Row and column index arrays for the lower triangle.
tril_indices_from
Return the indices for the lower triangle of a given array.| Name | Type | Default | Description |
|---|---|---|---|
a | ArrayLike | — | Input array. Must be at least 2-D. Uses the last two dimensions to determine the triangle. |
k | number | 0 | Diagonal offset. |
[NDArray, NDArray] — Row and column index arrays for the lower triangle.
triu_indices
Return the indices for the upper triangle of an (n, m) array.| Name | Type | Default | Description |
|---|---|---|---|
n | number | — | Number of rows in the array. |
k | number | 0 | Diagonal offset. k=0 is the main diagonal, k<0 is below it, k>0 is above it. |
m | number | n | Number of columns. Defaults to n (square array). |
[NDArray, NDArray] — Row and column index arrays for the upper triangle.
triu_indices_from
Return the indices for the upper triangle of a given array.| Name | Type | Default | Description |
|---|---|---|---|
a | ArrayLike | — | Input array. Must be at least 2-D. Uses the last two dimensions to determine the triangle. |
k | number | 0 | Diagonal offset. |
[NDArray, NDArray] — Row and column index arrays for the upper triangle.
mask_indices
Return the indices to access an (n, n) array given a masking function.| Name | Type | Default | Description |
|---|---|---|---|
n | number | — | Size of the square array. |
mask_func | (n: number, k?: number) => NDArray | — | A function that accepts (n, k) and returns a 2-D boolean or integer array (like triu or tril). |
k | number | 0 | Optional diagonal offset passed to mask_func. |
[NDArray, NDArray] — Row and column index arrays where mask_func returns non-zero values.
indices
Return an array representing the indices of a grid.| Name | Type | Default | Description |
|---|---|---|---|
dimensions | number[] | — | Shape of the grid. |
dtype | 'int32' | 'int64' | 'float64' | 'int32' | Data type of the result. |
NDArray dense grid with shape [N, ...dimensions].
ix_
Construct an open mesh from multiple sequences. This is useful for constructing index arrays for cross-indexing.| Name | Type | Default | Description |
|---|---|---|---|
...args | ArrayLike[] | — | 1-D sequences. Each sequence is reshaped so that it broadcasts against the others. |
NDArray[] — Tuple of N-D arrays with shapes (len(a0), 1, ..., 1), (1, len(a1), 1, ..., 1), etc.
fill_diagonal
Fill the main diagonal of the given array in-place.| Name | Type | Default | Description |
|---|---|---|---|
a | NDArray | — | Array to modify. Must be at least 2-D. |
val | number | ArrayLike | — | Value(s) to write on the diagonal. If an array, values are repeated cyclically to fill the entire diagonal. |
wrap | boolean | false | For tall matrices (rows > cols), if true, the diagonal wraps after reaching the last column. |
void — The array a is modified in-place.