I want to get a non-negative, nonzero min value from the tensor. Can someone help me to do this in an easy and efficient way
Will this work?
>>> x = (torch.rand((1,1,4,4)) * 2) - 1 # creating a tensor with a mixture of positive and negative value
>>> x
tensor([[[[ 0.8101, -0.5538, 0.2049, -0.8969],
[-0.5394, -0.8587, -0.5657, 0.0481],
[-0.9651, 0.8118, -0.3242, -0.5439],
[ 0.0358, -0.1856, -0.1928, 0.7507]]]])
>>> min_x = torch.min(x[x>0]) # taking non-negative non-zero min value from the tensor
>>> min_x
tensor(0.0358)