Find indices of elements equal to zero in a PyTorch Tensor
My question is nearly identical to this one, with the notable difference of being in PyTorch. I would prefer not to use the Numpy solution as this would involve moving data back to the CPU. I see that, as with Numpy, PyTorch has a nonzero function, however its where function (the solution in the Numpy thread I linked) has behavior different from Numpy's. 
The behavior I want is an is_zero() function as follows:

&gt;&gt;&gt; arr.nonzero()
tensor([[0, 1],
        [1, 0]])  
&gt;&gt;&gt; arr.is_zero()
tensor([[0, 0],
        [1, 1]])


You can make a boolean mask and then call nonzero():

(arr == 0).nonzero()


For instance:

arr = torch.randint(high=2, size=(3, 3))


tensor([[1, 1, 0],  # (0, 2)
        [1, 1, 0],  # (1, 2)
        [1, 0, 0]]) # (2, 1) and (2, 2)


(arr == 0).nonzero()


tensor([[0, 2],
        [1, 2],
        [2, 1],
        [2, 2]])

