PyTorch How to create a tensor with zero values

Below is the code which can be used to create a tensor with zero values:

torch.zeros(n, k)

Example:

torch.zeros(3, 3)

With the above example, we created a tensor of 3×3 size with zero values.

Complete sample code:

import torch

my_tensor = torch.zeros(3, 3)

print(my_tensor)

Output:

tensor([[0., 0., 0.],
        [0., 0., 0.],
        [0., 0., 0.]])