UNPKG

1.74 kBMarkdownView Raw
1<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
2
3# Function matrix
4
5Create a Matrix. The function creates a new `math.Matrix` object from
6an `Array`. A Matrix has utility functions to manipulate the data in the
7matrix, like getting the size and getting or setting values in the matrix.
8Supported storage formats are 'dense' and 'sparse'.
9
10
11## Syntax
12
13```js
14math.matrix() // creates an empty matrix using default storage format (dense).
15math.matrix(data) // creates a matrix with initial data using default storage format (dense).
16math.matrix('dense') // creates an empty matrix using the given storage format.
17math.matrix(data, 'dense') // creates a matrix with initial data using the given storage format.
18math.matrix(data, 'sparse') // creates a sparse matrix with initial data.
19math.matrix(data, 'sparse', 'number') // creates a sparse matrix with initial data, number data type.
20```
21
22### Parameters
23
24Parameter | Type | Description
25--------- | ---- | -----------
26`data` | Array &#124; Matrix | A multi dimensional array
27`format` | string | The Matrix storage format
28
29### Returns
30
31Type | Description
32---- | -----------
33Matrix | The created matrix
34
35
36## Examples
37
38```js
39let m = math.matrix([[1, 2], [3, 4]])
40m.size() // Array [2, 2]
41m.resize([3, 2], 5)
42m.valueOf() // Array [[1, 2], [3, 4], [5, 5]]
43m.get([1, 0]) // number 3
44```
45
46
47## See also
48
49[bignumber](bignumber.md),
50[boolean](boolean.md),
51[complex](complex.md),
52[index](index.md),
53[number](number.md),
54[string](string.md),
55[unit](unit.md),
56[sparse](sparse.md)