pytorch 两个tensor的交集

2024-01-03 16:39:39
  def tensor_intersect(self, t1, t2):
        # t1=t1.cuda()
        # t2=t2.cuda()
        indices = torch.zeros_like(t1, dtype = torch.bool, device = 'cuda')
        for elem in t2:
            indices = indices | (t1 == elem)  
            intersection = t1[indices]  
        return intersection

文章来源:https://blog.csdn.net/pain_gain0/article/details/135366209
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。