如果解决了你的问题,点个赞再走嘛?(?????)?
返回的是a矩阵的某个上三角矩阵,这个矩阵决定于k参数
当k=1时,取主对角线偏右上方的上三角矩阵,其余都为0
?代码:
import numpy as np
a = np.array([[1, 2, 3],
[4, 5, 6],
[7, 8, 9],
[1, 2, 3]])
print('np.triu(a,1)=\n', np.triu(a, 1))
print('np.triu(a,2)=\n', np.triu(a, 2))
print('np.triu(a,3)=\n', np.triu(a, 3))
print('np.triu(a,0)=\n', np.triu(a, 0))
print('np.triu(a,-1)=\n', np.triu(a, -1))
print('np.triu(a,-2)=\n', np.triu(a, -2))
结果:
np.triu(a,1)= ?[[0 2 3] ?[0 0 6] ?[0 0 0] ?[0 0 0]] np.triu(a,2)= ?[[0 0 3] ?[0 0 0] ?[0 0 0] ?[0 0 0]] np.triu(a,3)= ?[[0 0 0] ?[0 0 0] ?[0 0 0] ?[0 0 0]] np.triu(a,0)= ?[[1 2 3] ?[0 5 6] ?[0 0 9] ?[0 0 0]] np.triu(a,-1)= ?[[1 2 3] ?[4 5 6] ?[0 8 9] ?[0 0 3]] np.triu(a,-2)= ?[[1 2 3] ?[4 5 6] ?[7 8 9] ?[0 2 3]]
Process finished with exit code 0 ?
?如果解决了你的问题,点个赞再走嘛?(?????)?
|