UNPKG

1.45 kBMarkdownView Raw
1<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
2
3# Function getMatrixDataType
4
5Find the data type of all elements in a matrix or array,
6for example 'number' if all items are a number and 'Complex' if all values
7are complex numbers.
8If a matrix contains more than one data type, it will return 'mixed'.
9
10
11## Syntax
12
13```js
14math.getMatrixDataType(x)
15```
16
17### Parameters
18
19Parameter | Type | Description
20--------- | ---- | -----------
21`x` | ...Matrix &#124; Array | The Matrix with values.
22
23### Returns
24
25Type | Description
26---- | -----------
27string | A string representation of the matrix type
28
29
30## Examples
31
32```js
33const x = [ [1, 2, 3], [4, 5, 6] ]
34const mixedX = [ [1, true], [2, 3] ]
35const fractionX = [ [math.fraction(1, 3)], [math.fraction(1, 3] ]
36const unitX = [ [math.unit('5cm')], [math.unit('5cm')] ]
37const bigNumberX = [ [math.bignumber(1)], [math.bignumber(0)] ]
38const sparse = math.sparse(x)
39const dense = math.matrix(x)
40math.getMatrixDataType(x) // returns 'number'
41math.getMatrixDataType(sparse) // returns 'number'
42math.getMatrixDataType(dense) // returns 'number'
43math.getMatrixDataType(mixedX) // returns 'mixed'
44math.getMatrixDataType(fractionX) // returns 'Fraction'
45math.getMatrixDataType(unitX) // returns 'Unit'
46math.getMatrixDataType(bigNumberX) // return 'BigNumber'
47```
48
49
50## See also
51
52[SparseMatrix](SparseMatrix.md),
53[DenseMatrix](DenseMatrix.md)