UNPKG

1.26 kBMarkdownView Raw
1<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
2
3# Function sparse
4
5Create a Sparse 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.
8
9
10## Syntax
11
12```js
13math.sparse() // creates an empty sparse matrix.
14math.sparse(data) // creates a sparse matrix with initial data.
15math.sparse(data, 'number') // creates a sparse matrix with initial data, number datatype.
16```
17
18### Parameters
19
20Parameter | Type | Description
21--------- | ---- | -----------
22`data` | Array &#124; Matrix | A two dimensional array
23
24### Returns
25
26Type | Description
27---- | -----------
28Matrix | The created matrix
29
30
31## Examples
32
33```js
34let m = math.sparse([[1, 2], [3, 4]])
35m.size() // Array [2, 2]
36m.resize([3, 2], 5)
37m.valueOf() // Array [[1, 2], [3, 4], [5, 5]]
38m.get([1, 0]) // number 3
39```
40
41
42## See also
43
44[bignumber](bignumber.md),
45[boolean](boolean.md),
46[complex](complex.md),
47[index](index.md),
48[number](number.md),
49[string](string.md),
50[unit](unit.md),
51[matrix](matrix.md)