Does exist a PyTorch function to generate a tensor with constant values? In NumPy I would call np.full
.
So far, I have used:
constant = 3.0
t1 = torch.ones(3, 4) * constant
Does exist a PyTorch function to generate a tensor with constant values? In NumPy I would call np.full
.
So far, I have used:
constant = 3.0
t1 = torch.ones(3, 4) * constant
You can use .fill_()
:
t1 = torch.Tensor(3, 4).fill_(3.0)