Python torch.tril

您所在的位置:网站首页 torchtril Python torch.tril

Python torch.tril

2023-03-17 20:47| 来源: 网络整理| 查看: 265

返回 2-by-N 张量中 row -by- col 矩阵的下三角部分的索引,其中第一行包含所有索引的行坐标,第二行包含列坐标。索引先按行排序,然后按列排序。

矩阵的下三角部分定义为对角线上和下的元素。

参数 offset 控制要考虑的对角线。如果offset = 0,则保留主对角线上下的所有元素。正值包括与主对角线相同数量的对角线,同样,负值排除与主对角线下方相同数量的对角线。主对角线是i \in [0, \min\{d_{1}, d_{2}\} - 1] 的索引集\lbrace (i, i) \rbrace ,其中d_{1}, d_{2} 是矩阵的维度。

注意

在CUDA上运行时,row * col必须小于2^{59} ,以防止计算时溢出。

例子:

>>> a = torch.tril_indices(3, 3) >>> a tensor([[0, 1, 1, 2, 2, 2], [0, 0, 1, 0, 1, 2]]) >>> a = torch.tril_indices(4, 3, -1) >>> a tensor([[1, 2, 2, 3, 3, 3], [0, 0, 1, 0, 1, 2]]) >>> a = torch.tril_indices(4, 3, 1) >>> a tensor([[0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3], [0, 1, 0, 1, 2, 0, 1, 2, 0, 1, 2]])


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3