Function matrix

Create a 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. Supported storage formats are 'dense' and 'sparse'.

Syntax

matrix()                         // creates an empty matrix using default storage format (dense).
matrix(data)                     // creates a matrix with initial data using default storage format (dense).
matrix('dense')                  // creates an empty matrix using the given storage format.
matrix(data, 'dense')            // creates a matrix with initial data using the given storage format.
matrix(data, 'sparse')           // creates a sparse matrix with initial data.
matrix(data, 'sparse', 'number') // creates a sparse matrix with initial data, number data type.

Parameters

Parameter Type Description
data Array | Matrix A multi dimensional array
format string The Matrix storage format

Returns

Type Description
Matrix The created matrix

Examples

var m = matrix([[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, sparse