Home > @josh-brown/vector > MatrixBuilder > block
Constructs a single matrix consisting of a grid of matrices combined together. Throws an error if any of the dimensions are incompatible.
Signature:
block(grid: Matrix<S>[][]): M;|
Parameter |
Type |
Description |
|---|---|---|
|
grid |
Matrix<S>[][] |
A 2-dimensional array of matrices that will be combined into the new matrix |
Returns:
M
The new matrix
const upperLeft = matrixBuilder.ones(1, 1);
const upperRight = matrixBuilder.fill(2, 1, 2);
const lowerLeft = matrixBuilder.fill(3, 2, 1);
const lowerRight = matrixBuilder.fill(4, 2, 2);
const grid = [
[ upperLeft, upperRight ],
[ lowerLeft, lowerRight ]
];
const block = matrixBuilder.block(grid);
// [ 1 2 2 ]
// [ 3 4 4 ]
// [ 3 4 4 ]