Skip to content

Latest commit

 

History

History
114 lines (59 loc) · 1.62 KB

File metadata and controls

114 lines (59 loc) · 1.62 KB

Home > @josh-brown/vector > MatrixBuilder > triangularMask

MatrixBuilder.triangularMask() method

Constructs a matrix that has ones on and above the diagonal, and zeros elsewhere.

Signature:

triangularMask(shape: MatrixShape, lower?: boolean, includeDiagonal?: boolean): M;

Parameters

Parameter

Type

Description

shape

MatrixShape

The shape of the matrix as a tuple [m, n]

lower

boolean

(Optional) If true, the matrix will have ones below the diagonal rather than above. false by default.

includeDiagonal

boolean

(Optional) If false, entries on the diagonal will be zero. true by default.

Returns:

M

The triangular matrix

Example

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 ]