如何创建“岛屿”风格的pytorch矩阵
可能有一个简单的问题,希望有一个简单的解决方案:
我得到了(稀疏)1D布尔张量[1,n]
。
我想产生一个2D张量的大小[n,n]
,其中包含由1D张量诱导的岛屿。观察以下图像示例是最容易的,其中鞋面是1D布尔量张量,下面的矩阵表示所得的矩阵:
Probably a simple question, hopefully with a simple solution:
I am given a (sparse) 1D boolean tensor of size [1,N]
.
I would like to produce a 2D tensor our of it of size [N,N]
, containing islands which are induced by the 1D tensor. It will be the easiest to observe the following image example, where the upper is the 1D boolean tensor, and the matrix below represents the resulted matrix:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
给定一个蒙版输入:
您可以用 :
然后使用代码> 创建对角线块矩阵:
Given a mask input:
You can retrieve the indices with
torch.diff
:Then use
torch.block_diag
to create the diagonal block matrix: