I have a 2D tensor with some nonzero element in each row like this:
import torch tmp = torch.tensor([[0, 0, 1, 0, 1, 0, 0], [0, 0, 0, 1, 1, 0, 0]], dtype=torch.float) I want a tensor containing the index of first nonzero element in each row:
indices = tensor([2], [3]) How can I calculate it in Pytorch?