Skip to content

Latest commit

 

History

History
83 lines (41 loc) · 1.22 KB

File metadata and controls

83 lines (41 loc) · 1.22 KB

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

MatrixBuilder.fromIndexFunction() method

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;

Parameters

Parameter

Type

Description

shape

MatrixShape

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

indexFunction

(i: number, j: number) => S

A function returning the entry for a given i, j

Returns:

M

The new matrix

Example

const matrix = matrixBuilder.fromIndexFunction(3, 4, (i, j) => i + j + 3);

// [ 3 4 5 6 ]
// [ 4 5 6 7 ]
// [ 5 6 7 8 ]