The question says it all. I want to get a 2-D torch.Tensor with size [a,b] filled with values from a uniform distribution (in range [r1,r2]
torch.Tensor
[a,b]
[r1,r2]
This answer uses NumPy to first produce a random matrix and then converts the matrix to a PyTorch tensor. I find the NumPy API to be easier to understand.
import numpy as np torch.from_numpy(np.random.uniform(low=r1, high=r2, size=(a, b)))