Create tensor having all elements set to 2

Hello!
I want to check whether each value of a tensor of shape [1, 1, 16, 16] is greater than 2. I tried doing it simply by

if(myTensor > 2)

but it throws the following error:

RuntimeError: Boolean value of Tensor with more than one value is ambiguous

Is there any way to create a tensor of shape [1, 1, 16, 16] with all its values set to 2. Will I then be able to compare each individual value of myTensor with 2?

The if condition expects a single True or False statement while your comparison myTensor > 2 could yield multiple outputs as it’s an elementwise comparison.
If you want to check if all values in myTensor are > 2 you could use:

if (myTensor > 2).all():

To create a tensor with all values set to 2 you could use:

myTensor = torch.full((1, 1, 16, 16), fill_value=2.)

Thank you. That worked!