Home > @josh-brown/vector > MatrixBuilder > triangularMask
Constructs a matrix that has ones on and above the diagonal, and zeros elsewhere.
Signature:
triangularMask(shape: MatrixShape, lower?: boolean, includeDiagonal?: boolean): M;|
Parameter |
Type |
Description |
|---|---|---|
|
shape |
The shape of the matrix as a tuple | |
|
lower |
boolean |
(Optional) If |
|
includeDiagonal |
boolean |
(Optional) If |
Returns:
M
The triangular matrix
const upper = matrixBuilder.triangularMask([4, 4]);
// [ 1 1 1 1 ]
// [ 0 1 1 1 ]
// [ 0 0 1 1 ]
// [ 0 0 0 1 ]
const lower = matrixBuilder.triangularMask([4, 4], true);
// [ 1 0 0 0 ]
// [ 1 1 0 0 ]
// [ 1 1 1 0 ]
// [ 1 1 1 1 ]
const strictUpper = matrixBuilder.triangularMask([4, 4], false, false);
// [ 0 1 1 1 ]
// [ 0 0 1 1 ]
// [ 0 0 0 1 ]
// [ 0 0 0 0 ]