python - 为什么 return np.random.normal(10 - 1./(x + 0.1), 0.5) 有效

标签 python list numpy random parameters

正如我们在 numpy.random.normal 的文档中看到的那样

numpy.random.normal(loc=0.0, scale=1.0, size=None) Draw random samples from a normal (Gaussian) distribution.

The probability density function of the normal distribution, first derived by De Moivre and 200 years later by both Gauss and Laplace independently [R217], is often called the bell curve because of its characteristic shape (see the example below).

The normal distributions occurs often in nature. For example, it describes the commonly occurring distribution of samples influenced by a large number of tiny, random disturbances, each with its own unique distribution [R217]. Parameters:

loc : float

Mean (“centre”) of the distribution.

scale : float

Standard deviation (spread or “width”) of the distribution.

size : int or tuple of ints, optional

Output shape. If the given shape is, e.g., (m, n, k), then m * n * k samples are drawn. Default is None, in which case a single value is returned.

那么为什么当 x = 10**np.linspace(-2, 0, 8)

  • 参数loc应该是float吗?
  • 如果有效,其含义是什么?

最佳答案

您的代码绘制 8 个数字,每个数字都来自不同的高斯分布。 x 的值被视为分布参数,但每个值都用于生成该分布中的一个样本。

您的代码相当于:

np.random.normal(np.zeros(8), 0.5) + 10 - 1. / (x + 0.1)

即使用正态分布生成 8 个数字并将它们移位 x。

关于python - 为什么 return np.random.normal(10 - 1./(x + 0.1), 0.5) 有效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29124183/

相关文章:

java - java中递归地将字符串追加到字符串列表中

python - 匹配字典列表最有效的方法是什么?

python - numpy 中是否有 searchsorted 的词法版本?

python - 有没有更好的方法来重写这个 NumPy 片段

Python Tkinter : textfield enter command

python - XGBoost的损失函数和评价指标

r - 使用每个小标题中的名称从小标题列表中选择变量

python - 如何释放类型化的 numpy 数组?设置 callback_free_data 是一个可行的选择吗?

python - 为什么 super().__init__ 没有自引用?

python - Pyopengl - 从 VBO 绘制的几条线但是索引颜色 VBO 不起作用