Matrix<T>
以行优先顺序存储的 T 类型元素的二维表。
种类: object
静态方法
new
Matrix.new(
rows: int = 0,
columns: int = 0,
initial_value: T = na
): const Matrix<T>Creates a new matrix with the specified number of rows and columns, initializing all elements to the given initial value.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
rows | int | 0 | The number of rows in the matrix. |
columns | int | 0 | The number of columns in the matrix. |
initial_value | T | na | The initial value for all elements. |
返回: const Matrix<T>
方法
add_col
Matrix.add_col(id: Matrix<T>, column: int = na, values: Array<T> = na)将新列添加到给定列索引处的指定矩阵,用提供的值填充它,如果没有给出值,则用 na 填充。
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
id | Matrix<T> | 将添加列的矩阵。 | |
column | int | na | 将插入列的索引。省略时,最后一列位置。 |
values | Array<T> | na | 用于填充列的值数组,或用 na 值填充 na。 |
add_row
Matrix.add_row(id: Matrix<T>, row: int = na, values: Array<T> = na)将新行添加到指定矩阵的给定行索引处,用提供的值填充它,如果没有给出值,则用 na 填充。
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
id | Matrix<T> | 将添加行的矩阵。 | |
row | int | na | 将插入行的索引。省略时,最后一行位置。 |
values | Array<T> | na | 用于填充行的值数组,或用 na 值填充 na。 |
avg
col
Matrix.col(id: Matrix<T>, column: int): Array<T>从矩阵的指定列检索所有元素并将它们作为数组返回。
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
id | Matrix<T> | 要从中检索列的矩阵。 | |
column | int | 要检索的列索引。 |
返回: Array<T>
columns
Matrix.columns(id: Matrix<T>): int返回指定矩阵中的列数。
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
id | Matrix<T> | 从中获取列数的矩阵。 |
返回: int
concat
Matrix.concat(id1: Matrix<T>, id2: Matrix<T>)将两个相同类型的矩阵连接到 mat1 并返回 mat1。
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
id1 | Matrix<T> | 要连接的第一个矩阵。 | |
id2 | Matrix<T> | 要连接的第二个矩阵。 |
copy
Matrix.copy(id: Matrix<T>)创建给定矩阵的拷贝并返回新矩阵。
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
id | Matrix<T> | 要复制的矩阵。 |
det
diff
计算相同维度的两个矩阵之间的逐元素差异,并返回包含结果的新矩阵。
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
id1 | Matrix<int> | 第一个整数矩阵。 | |
id2 | Matrix<int> | 第二个整数矩阵。 |
返回: Matrix<int>
eigenvalues
eigenvectors
elements_count
Matrix.elements_count(id: Matrix<T>): int通过将指定矩阵的行数乘以其列数来返回指定矩阵中的元素总数。
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
id | Matrix<T> | 要计算其元素数量的矩阵。 |
返回: int
fill
Matrix.fill(
id: Matrix<T>,
value: T,
from_row: int = 0,
to_row: int = id.rows(),
from_column: int = 0,
to_column: int = id.columns()
)用指定值填充给定矩阵的指定子矩阵。子矩阵由作为参数提供的行和列范围定义。
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
id | Matrix<T> | 要填充的矩阵。 | |
value | T | 用于填充子矩阵的值。 | |
from_row | int | 0 | 起始行索引。 |
to_row | int | id.rows() | 结束行索引。省略时,表示矩阵行数。 |
from_column | int | 0 | 起始列索引。 |
to_column | int | id.columns() | 结束列索引。省略时,表示矩阵列数。 |
get
Matrix.get(id: Matrix<T>, row: int, column: int): T从给定矩阵中检索指定行索引和列索引处的值。
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
id | Matrix<T> | 要从中检索值的矩阵。 | |
row | int | 元素的行索引。 | |
column | int | 元素的列索引。 |
返回: T
inv
is_antidiagonal
is_antisymmetric
is_binary
is_diagonal
is_identity
is_square
Matrix.is_square(id: Matrix<T>): bool检查给定矩阵是否为方阵,如果是则返回 true,否则返回 false。
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
id | Matrix<T> | 要检查的矩阵。 |
返回: bool
is_stochastic
is_symmetric
is_triangular
is_zero
kron
max
median
min
mode
multi
pinv
pow
rank
remove_col
Matrix.remove_col(id: Matrix<T>, column: int = na): Array<T>从给定矩阵中删除指定列并将删除的列作为数组返回。如果未提供列索引,则默认删除最后一列。
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
id | Matrix<T> | 将从中删除列的矩阵。 | |
column | int | na | 要删除的列的索引。省略时,最后一列。 |
返回: Array<T> — 包含已删除列的元素的数组。
remove_row
Matrix.remove_row(id: Matrix<T>, row: int = na): Array<T>从给定矩阵中删除指定行并将删除的行作为数组返回。如果未提供行索引,则默认删除最后一行。
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
id | Matrix<T> | 将从中删除行的矩阵。 | |
row | int | na | 要删除的行的索引。省略时,最后一行。 |
返回: Array<T> — 包含已删除行的元素的数组。
reshape
Matrix.reshape(id: Matrix<T>, rows: int, columns: int)将给定矩阵重塑为指定的行数和列数。
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
id | Matrix<T> | 要重塑的矩阵。 | |
rows | int | 新的行数。 | |
columns | int | 新的列数。 |
reverse
Matrix.reverse(id: Matrix<T>)就地反转指定矩阵中元素的顺序。
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
id | Matrix<T> | 要反转的矩阵。 |
row
Matrix.row(id: Matrix<T>, row: int): Array<T>从矩阵的指定行检索所有元素并将它们作为数组返回。
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
id | Matrix<T> | 要从中检索行的矩阵。 | |
row | int | 要检索的行索引。 |
返回: Array<T>
rows
Matrix.rows(id: Matrix<T>): int返回指定矩阵中的行数。
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
id | Matrix<T> | 从中获取行数的矩阵。 |
返回: int
set
Matrix.set(id: Matrix<T>, row: int, column: int, value: T)将给定矩阵中指定行索引和列索引处的值设置为提供的值。
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
id | Matrix<T> | 要修改的矩阵。 | |
row | int | 元素的行索引。 | |
column | int | 元素的列索引。 | |
value | T | 要在指定位置设置的值。 |
sort
subMatrix
Matrix.subMatrix(
id: Matrix<T>,
from_row: int = 0,
to_row: int = id.rows(),
from_column: int = 0,
to_column: int = id.columns()
): Matrix<T>根据指定的行和列范围从给定矩阵中提取子矩阵并返回新的子矩阵。
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
id | Matrix<T> | 从中提取子矩阵的矩阵。 | |
from_row | int | 0 | 起始行索引。 |
to_row | int | id.rows() | 结束行索引。省略时,表示矩阵行数。 |
from_column | int | 0 | 起始列索引。 |
to_column | int | id.columns() | 结束列索引。省略时,表示矩阵列数。 |
返回: Matrix<T>
sum
swap_columns
Matrix.swap_columns(id: Matrix<T>, column1: int, column2: int)交换指定矩阵中的两列。
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
id | Matrix<T> | 包含要交换的列的矩阵。 | |
column1 | int | 第一列的索引。 | |
column2 | int | 第二列的索引。 |
swap_rows
Matrix.swap_rows(id: Matrix<T>, row1: int, row2: int)交换指定矩阵中的两行。
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
id | Matrix<T> | 包含要交换的行的矩阵。 | |
row1 | int | 第一行的索引。 | |
row2 | int | 第二行的索引。 |
trace
transpose
Matrix.transpose(id: Matrix<T>): Matrix<T>转置给定矩阵并返回新的转置矩阵。
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
id | Matrix<T> | 要转置的矩阵。 |
返回: Matrix<T>