There seems to be multiple ways of initializing a tensor from a distribution, for example if we want to sample from a uniform distribution I found this can be done by:
Method 1
from torch.distributions.uniform import Uniform
U = Uniform(low=torch.tensor([0.0]), high=torch.tensor([1.0]))
samples = U.sample(sample_shape=(5,5)) # This shape turns out 5x5x1 (?)

Method 2
w = torch.empty(3,  5)
nn.init.uniform_(w, a=0, b=1)

Method 3
# The arguments seem to be uniform_(from, to) but writing from gives
# me an error because it is a keyword
w = torch.empty(3, 5).uniform_(0, to=2)

Perhaps there are more ways to do this that I’ve missed. I feel using the nn.init seems to make sense, but from https://pytorch.org/docs/stable/nn.init.html 1 it seems to be quite lacking in comparison to https://pytorch.org/docs/stable/distributions.html.
Question:
Which method is recommended to use and is there a reason why we have multiple ways of doing it? All of these methods are also a little bit different than the way numpy does it which seems to be most intuitive to me: s = np.random.uniform(low=0, high=1, size=(1, 5))