TriU
TriU
返回矩阵的副本,其中第 k 个对角线下方的元素归零。 上三角形矩阵。
matrix matrix::Triu(
const int ndiag=0 // 对角线的索引
);参数
- ndiag=0
[输入] 对角线之下的元素为零。 ndiag = 0(默认值)是主对角线,ndiag < 0 在其下方,ndiag > 0 位于其上方。
MQL5 示例:
matrix a={{1,2,3},{4,5,6},{7,8,9},{10,11,12}};
matrix b=a.TriU(-1);
Print("matrix b \n",b);
/*
matrix b
[[1,2,3]
[4,5,6]
[0,8,9]
[0,0,12]]
*/Python 示例:
import numpy as np
a=np.triu([[1,2,3],[4,5,6],[7,8,9],[10,11,12]], -1)
print(a)
[[ 1 2 3]
[ 4 5 6]
[ 0 8 9]
[ 0 0 12]]