rand() - Returns a tensor filled with random numbers from a uniform distribution on the interval [0, 1)
torch.rand(100)
tensor([0.7880, 0.3032, 0.3627, 0.7082, 0.1795, 0.4985, 0.9594, 0.7900, 0.9585, 0.9081, 0.1518, 0.7774, 0.5773, 0.7038, 0.6504, 0.5719, 0.1926, 0.9394, 0.6213, 0.8958, 0.4246, 0.5511, 0.9647, 0.1502, 0.7306, 0.8174, 0.7219, 0.3699, 0.6787, 0.8045, 0.1807, 0.6873, 0.7628, 0.2076, 0.3093, 0.9894, 0.0346, 0.4468, 0.5628, 0.4541, 0.2028, 0.0766, 0.9851, 0.0201, 0.7290, 0.2190, 0.5702, 0.4273, 0.9675, 0.5790, 0.0305, 0.1053, 0.2790, 0.2650, 0.1109, 0.9617, 0.1193, 0.1121, 0.8944, 0.0246, 0.7383, 0.6698, 0.6169, 0.9427, 0.0242, 0.1348, 0.8053, 0.8895, 0.4818, 0.1180, 0.3640, 0.5278, 0.6612, 0.6710, 0.4686, 0.3391, 0.3898, 0.8033, 0.8198, 0.2833, 0.8570, 0.1580, 0.6899, 0.1758, 0.3869, 0.7366, 0.9442, 0.1048, 0.6854, 0.1650, 0.9399, 0.5242, 0.9021, 0.1574, 0.4322, 0.0012, 0.4553, 0.1467, 0.4122, 0.6095])
randn() - Returns a tensor filled with random numbers from a normal distribution with mean 0
and variance 1
(also called the standard normal distribution).
dummy_randn = torch.randn(100) dummy_randn
tensor([ 0.2083, -0.1248, 1.6377, 0.4158, -0.7428, -0.4556, 0.0847, 0.6920, -0.5236, 2.8119, 0.7568, 1.6511, 0.9284, -0.7238, 0.8877, -1.5698, 0.6462, -0.4516, 0.4115, -0.5270, -0.9781, 0.1980, 1.8830, -0.1075, -2.4378, 0.3186, -0.3314, -0.5624, 0.9069, -1.4985, -0.4653, -0.8702, -1.5003, 0.9597, 1.0643, 1.1367, 0.2547, 1.4202, -0.7661, -0.2886, -0.4551, -0.7584, -1.8408, 0.1006, -0.8138, 0.9638, -1.1081, 1.2978, -1.1531, -1.4703, -0.2286, -0.0533, 0.1332, 1.4026, 1.3106, 0.2118, 0.3589, 0.8719, -0.5595, -1.2247, -1.0900, 0.1247, -0.2331, -0.1365, -0.4995, 0.5812, 0.4895, 1.4686, -0.4431, 1.4738, -0.7067, 1.2377, 0.8108, -1.5416, -0.0712, -0.1495, -0.0450, -1.3758, 1.6389, -0.3777, -0.5939, 0.5944, 0.8223, -1.8278, 1.3142, -0.7945, 0.7133, -0.4062, 0.0681, 1.4935, -0.8036, -0.6210, 1.1735, -2.2997, -0.2382, -1.9110, 0.1857, 1.2263, 0.2231, -1.6662])
dummy_randn.mean(), dummy_randn.var() # (tensor(-0.0086), tensor(1.0671))
标签:rand,randn,tensor,dummy,random,PyTorch,distribution,Difference From: https://www.cnblogs.com/zhangzhihui/p/18512227