Check any one value in tensor is zero or not

I want to check any one value in tensor is zero or not. For below program it shows “RuntimeError: Boolean value of Tensor with more than one value is ambiguous”

import torch
a=torch.tensor((torch.rand(4)))
a[1]=0
print(a)
if(a!=0):
  print("All value is non zero")
else:
  print("Atleast one value is zero")

You can use .all()

import torch
a=torch.rand(4, 4)
a[1]=0

if a.all():
    print("All values are non zero")
else:
    print("At least one value is zero")
2 Likes