Skip to content

Latest commit

 

History

History
72 lines (39 loc) · 1.1 KB

File metadata and controls

72 lines (39 loc) · 1.1 KB

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

MatrixBuilder.blockDiagonal() method

Creates a block-diagonal matrix.

Signature:

blockDiagonal(matrices: Matrix<S>[]): M;

Parameters

Parameter

Type

Description

matrices

Matrix<S>[]

The matrices to appear along the primary diagonal of the block matrix

Returns:

M

Example

const ones = matrixBuilder.ones(2);
const twos = matrixBuilder.fill(2, 3);

const blockDiagonal = matrixBuilder.blockDiagonal([ones, twos, ones]);

// [ 1 1 0 0 0 0 0 ]
// [ 1 1 0 0 0 0 0 ]
// [ 0 0 2 2 2 0 0 ]
// [ 0 0 2 2 2 0 0 ]
// [ 0 0 2 2 2 0 0 ]
// [ 0 0 0 0 0 1 1 ]
// [ 0 0 0 0 0 1 1 ]