eye
Return a 2-D array with ones on the diagonal and zeros elsewhere.| Name | Type | Default | Description |
|---|---|---|---|
n | number | - | Number of rows. |
m | number | n | Number of columns. Defaults to n (square matrix). |
k | number | 0 | Index of the diagonal. 0 is the main diagonal, positive values are above, negative below. |
dtype | DType | 'float64' | Data type of the output array. |
NDArray — 2-D array of shape [n, m] with ones on the k-th diagonal.
identity
Return the identity matrix (a square matrix with ones on the main diagonal).| Name | Type | Default | Description |
|---|---|---|---|
n | number | - | Number of rows (and columns) in the output. |
dtype | DType | 'float64' | Data type of the output array. |
NDArray — n x n identity matrix.
diag
Extract a diagonal or construct a diagonal array. When given a 1-D array, returns a 2-D array with the input as itsk-th diagonal. When given a 2-D array, extracts the k-th diagonal.
| Name | Type | Default | Description |
|---|---|---|---|
v | ArrayLike | - | Input array. If 1-D, used as a diagonal to build a 2-D matrix. If 2-D, the k-th diagonal is extracted. |
k | number | 0 | Diagonal index. 0 is the main diagonal. Positive is above, negative is below. |
NDArray — Extracted diagonal (1-D) or constructed diagonal matrix (2-D).
diagflat
Create a diagonal matrix from a flattened input.| Name | Type | Default | Description |
|---|---|---|---|
v | ArrayLike | - | Input array. It is flattened before being placed on the diagonal. |
k | number | 0 | Diagonal offset. |
NDArray — 2-D array with the flattened v on the k-th diagonal.
tri
Return an array with ones at and below the given diagonal and zeros elsewhere.| Name | Type | Default | Description |
|---|---|---|---|
N | number | - | Number of rows. |
M | number | N | Number of columns. |
k | number | 0 | Diagonal above which to fill with zeros. k = 0 is the main diagonal. |
dtype | DType | 'float64' | Data type of the output array. |
NDArray — Lower-triangular array of shape [N, M].
tril
Return the lower triangle of an array. Elements above thek-th diagonal are zeroed.
| Name | Type | Default | Description |
|---|---|---|---|
m | ArrayLike | - | Input array (must be at least 2-D). |
k | number | 0 | Diagonal above which to zero elements. 0 keeps the main diagonal. |
NDArray — Copy of m with elements above the k-th diagonal zeroed.
triu
Return the upper triangle of an array. Elements below thek-th diagonal are zeroed.
| Name | Type | Default | Description |
|---|---|---|---|
m | ArrayLike | - | Input array (must be at least 2-D). |
k | number | 0 | Diagonal below which to zero elements. |
NDArray — Copy of m with elements below the k-th diagonal zeroed.
vander
Generate a Vandermonde matrix. Columnj of the output is x**j (when increasing is true) or x**(N-1-j) (the default).
| Name | Type | Default | Description |
|---|---|---|---|
x | ArrayLike | - | 1-D input array. |
N | number | x.length | Number of columns in the output. |
increasing | boolean | false | If true, powers increase left to right. |
NDArray — Vandermonde matrix of shape [x.length, N].