Function sparse

Create a Sparse Matrix. The function creates a new type.Matrix object from an Array. A Matrix has utility functions to manipulate the data in the matrix, like getting the size and getting or setting values in the matrix.

Syntax

sparse()               // creates an empty sparse matrix.
sparse(data)           // creates a sparse matrix with initial data.
sparse(data, 'number') // creates a sparse matrix with initial data, number datatype.

Parameters

Parameter Type Description
data Array | Matrix A two dimensional array

Returns

Type Description
Matrix The created matrix

Examples

var m = sparse([[1, 2], [3, 4]]);
m.size();                        // Array [2, 2]
m.resize([3, 2], 5);
m.valueOf();                     // Array [[1, 2], [3, 4], [5, 5]]
m.get([1, 0])                    // number 3

See also

bignumber, boolean, complex, number, string, unit, matrix