nonzero() 以张量的形式返回非0元素的索引,不管有几维,维度索引都放在一个“列表”中 import torch a =torch.Tensor([1,2,4,4,5]) print(torch.nonzero(a<4)) torch.unique() 挑出tensor中的独立不重复元素。