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