YouTip LogoYouTip

Pytorch Torch Nonzero

# Return the indices of non-zero elements indices = torch.nonzero(x) print("Non-zero element indices:") print(indices)

Output result is:

Non-zero element indices: tensor([[0, 1], [1, 0], [2, 1]])

Image 4: Pytorch torch Reference Manual Pytorch torch Reference Manual

← Pytorch Torch NormalPytorch Torch Nextafter β†’