Advertisement

PyTorch学习 torch.scatter的使用

阅读量:

总说

一个具有重要实用价值的函数,其核心功能在于实现对“group index”的相关操作。

接下来请先完成 https://github.com/rusty1s/pytorch_scatter 的安装步骤。

复制代码
    from torch_scatter import scatter
    import torch
    
    src = (torch.rand(2, 6, 2)*4).int()
    index = torch.tensor([0, 1, 0, 1, 2, 1])
    
    # Broadcasting in the first and last dim.
    out = scatter(src, index, dim=1, reduce="sum")
    
    print(src)
    print(index)
    print(out)
    
    
    
      
      
      
      
      
      
      
      
      
      
      
      
      
    
复制代码
    tensor([[[1, 3],
         [3, 3],
         [3, 2],

全部评论 (0)

还没有任何评论哟~