【numpy】np.triu的使用

every blog every motto: You can do more than you think.
https://blog.csdn.net/weixin_39190382?type=blog

0. 前言

np.triu使用,参数辨析

1. 正文

import numpy as np

arr = np.ones((3,3))
print(arr)

在这里插入图片描述

print(np.triu(arr,0))

0时,包含对角线上的元素
在这里插入图片描述

print(np.triu(arr,1))

1时,向右上移动“一行”
在这里插入图片描述
2,同理
在这里插入图片描述

-1 时,从主对角线往左下移动“一行”
在这里插入图片描述
换成4*4 ,看的更加清楚
在这里插入图片描述
-2时,在忘左下移动“一行”
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_39190382/article/details/134783347
今日推荐