[Learning] to generate a random number PyTorch

torch.rand

Returns a tensor, comprising from interval [0, 1) in uniform distribution a set of random numbers are drawn. Tensor is defined by a shape parameter sizes.


tmp = torch.rand(2, 3)


torch.randn

Returns a tensor, comprising a set of random numbers extracted from the standard normal distribution (mean 0 and variance 1, i.e., Gaussian white noise) in the. Tensor is defined by a shape parameter sizes.

tmp = torch.randn(2, 3)

 


torch.normal

Returns a tensor, comprising a set of random numbers extracted from the specified means the mean and standard deviation std discrete normal distribution.

Standard deviation std is a tensor, comprising a standard normal distribution associated with each element of the output difference.

print(torch.normal(mean=0.5, std=torch.arange(1, 6).float()))

 


torch.linspace

Returns a 1-dimensional tensor, comprising a step points in the interval start and end uniformly spaced.

Tensor length of the output is determined by the steps.

print(torch.linspace(1, 10, steps=4))

 

 

 

 

Published 83 original articles · won praise 14 · views 30000 +

Guess you like

Origin blog.csdn.net/weixin_38121168/article/details/103097474