Skip to main content

eye

Return a 2-D array with ones on the diagonal and zeros elsewhere.
Returns: 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).
Returns: NDArrayn 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 its k-th diagonal. When given a 2-D array, extracts the k-th diagonal.
Returns: NDArray — Extracted diagonal (1-D) or constructed diagonal matrix (2-D).

diagflat

Create a diagonal matrix from a flattened input.
Returns: 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.
Returns: NDArray — Lower-triangular array of shape [N, M].

tril

Return the lower triangle of an array. Elements above the k-th diagonal are zeroed.
Returns: NDArray — Copy of m with elements above the k-th diagonal zeroed.

triu

Return the upper triangle of an array. Elements below the k-th diagonal are zeroed.
Returns: NDArray — Copy of m with elements below the k-th diagonal zeroed.

vander

Generate a Vandermonde matrix. Column j of the output is x**j (when increasing is true) or x**(N-1-j) (the default).
Returns: NDArray — Vandermonde matrix of shape [x.length, N].