Home > @josh-brown/vector > MatrixBuilder > fromIndexFunction
Builds a matrix with entries given by _entry = f(i, j)_ where _f_ is indexFunction and i and j are the indices of the element
Signature:
fromIndexFunction(shape: MatrixShape, indexFunction: (i: number, j: number) => S): M;|
Parameter |
Type |
Description |
|---|---|---|
|
shape |
The shape of the matrix as a tuple | |
|
indexFunction |
(i: number, j: number) => S |
A function returning the entry for a given |
Returns:
M
The new matrix
const matrix = matrixBuilder.fromIndexFunction(3, 4, (i, j) => i + j + 3);
// [ 3 4 5 6 ]
// [ 4 5 6 7 ]
// [ 5 6 7 8 ]