【发布时间】:2019-07-12 17:51:32
【问题描述】:
我有两点要问:
1)
我想了解 NumPy 的 np.random.randn 和 PyTorch 的 torch.randn 究竟返回了什么。它们都从均值为 0 和标准为 1 的正态分布中返回具有随机数的张量,因此是标准正态分布。但是,这与将x 值放入标准正态分布函数here 并获取其各自的图像值y 不同。 PyTorch 和 NumPy 返回的值看起来不是这样的。
对我来说,这些库中的np.random.randn 和torch.randn 似乎都从函数返回x 值,而不是我在下面计算的图像y。对吗?
normal = np.array([(1/np.sqrt(2*np.pi))*np.exp(-(1/2)*(i**2)) for i in range(-38,39)])
打印normal 变量向我展示了类似的内容。
array([1.10e-314, 2.12e-298, 1.51e-282, 3.94e-267, 3.79e-252, 1.34e-237,
1.75e-223, 8.36e-210, 1.47e-196, 9.55e-184, 2.28e-171, 2.00e-159,
6.45e-148, 7.65e-137, 3.34e-126, 5.37e-116, 3.17e-106, 6.90e-097,
5.52e-088, 1.62e-079, 1.76e-071, 7.00e-064, 1.03e-056, 5.53e-050,
1.10e-043, 8.00e-038, 2.15e-032, 2.12e-027, 7.69e-023, 1.03e-018,
5.05e-015, 9.13e-012, 6.08e-009, 1.49e-006, 1.34e-004, 4.43e-003,
5.40e-002, 2.42e-001, 3.99e-001, 2.42e-001, 5.40e-002, 4.43e-003,
1.34e-004, 1.49e-006, 6.08e-009, 9.13e-012, 5.05e-015, 1.03e-018,
7.69e-023, 2.12e-027, 2.15e-032, 8.00e-038, 1.10e-043, 5.53e-050,
1.03e-056, 7.00e-064, 1.76e-071, 1.62e-079, 5.52e-088, 6.90e-097,
3.17e-106, 5.37e-116, 3.34e-126, 7.65e-137, 6.45e-148, 2.00e-159,
2.28e-171, 9.55e-184, 1.47e-196, 8.36e-210, 1.75e-223, 1.34e-237,
3.79e-252, 3.94e-267, 1.51e-282, 2.12e-298, 1.10e-314])
2) 另外,如果我们问这些库我想要一个来自标准正态分布的值矩阵,这是否意味着所有行和列都来自相同的标准分布?如果我想要每一行中的 i.i.d 分布,我需要通过for 循环为每一行调用np.random.randn,然后vstack 它们?
【问题讨论】:
标签: python-3.x numpy pytorch probability-distribution