Identity
Identity
它是一个静态函数,可创建指定大小(不一定是正方形)的单位矩阵。 一个单位矩阵在主对角线上包含 0,在其它所在包含零。 主对角线由行索引和列索引相等的矩阵元素组成,譬如 [0,0]、[1,1]、[2,2],等等。 创建一个新的单位矩阵。
还有一个 Identity 方法能将已经存在的矩阵转换为单位矩阵。
static matrix matrix::Identity(
const ulong rows, // 行数
const ulong cols, // 列数
);
void matrix::Identity();参数
- rows
[输入] n x n 矩阵中的行数(和列数)。
返回值
返回单位矩阵。 单位矩阵是一个方阵,主对角线上为 1。
MQL5 示例:
matrix identity=matrix::Identity(3,3);
Print("identity = \n", identity);
/*
identity =
[[1,0,0]
[0,1,0]
[0,0,1]]
*/
matrix identity2(3,5);
identity2.Identity();
Print("identity2 = \n", identity2);
/*
identity2 =
[[1,0,0,0,0]
[0,1,0,0,0]
[0,0,1,0,0]]
*/Python 示例:
np.identity(3)
array([[1., 0., 0.],
[0., 1., 0.],
[0., 0., 1.]])