sparse.md (1263B)
1 <!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. --> 2 3 # Function sparse 4 5 Create a Sparse Matrix. The function creates a new `math.Matrix` object from 6 an `Array`. A Matrix has utility functions to manipulate the data in the 7 matrix, like getting the size and getting or setting values in the matrix. 8 9 10 ## Syntax 11 12 ```js 13 math.sparse() // creates an empty sparse matrix. 14 math.sparse(data) // creates a sparse matrix with initial data. 15 math.sparse(data, 'number') // creates a sparse matrix with initial data, number datatype. 16 ``` 17 18 ### Parameters 19 20 Parameter | Type | Description 21 --------- | ---- | ----------- 22 `data` | Array | Matrix | A two dimensional array 23 24 ### Returns 25 26 Type | Description 27 ---- | ----------- 28 Matrix | The created matrix 29 30 31 ## Examples 32 33 ```js 34 let m = math.sparse([[1, 2], [3, 4]]) 35 m.size() // Array [2, 2] 36 m.resize([3, 2], 5) 37 m.valueOf() // Array [[1, 2], [3, 4], [5, 5]] 38 m.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)