函数 matrix #
创建一个 Matrix。该函数从一个 Array 创建一个新的 math.Matrix 对象。Matrix 包含用于操作矩阵数据的实用函数,例如获取大小以及获取或设置矩阵中的值。支持的存储格式有 ‘dense’ 和 ‘sparse’。
Syntax #
math.matrix() // creates an empty matrix using default storage format (dense).
math.matrix(data) // creates a matrix with initial data using default storage format (dense).
math.matrix('dense') // creates an empty matrix using the given storage format.
math.matrix(data, 'dense') // creates a matrix with initial data using the given storage format.
math.matrix(data, 'sparse') // creates a sparse matrix with initial data.
math.matrix(data, 'sparse', 'number') // creates a sparse matrix with initial data, number data type.
Parameters #
| Parameter | Type | Description |
|---|---|---|
data |
Array | Matrix | 多维数组 |
format |
string | Matrix 存储格式,可以是 'dense' 或 'sparse' |
数据类型 |
string | 值的类型 |
Returns #
| Type | Description |
|---|---|
| 矩阵 | 创建的矩阵 |
Throws #
Type | Description —- | ———–
Examples #
let m = math.matrix([[1, 2], [3, 4]])
m.size() // Array [2, 2]
m.resize([3, 2], 5)
m.valueOf() // Array [[1, 2], [3, 4], [5, 5]]
m.get([1, 0]) // number 3
另请参阅 #
bignumber, boolean, complex, index, number, string, unit, sparse