数组名称下划线含义

3

我对下面的示例代码有一个问题。我确定传递给gp.predict行的值是来自X数组的值。但是,为什么它被用作X_?能有人解释一下在Python中X_或者一个数组name_代表什么意思吗?

rng = np.random.RandomState(4)
X = rng.uniform(0, 5, 10)[:, np.newaxis]
y = np.sin((X[:, 0] - 2.5) ** 2)
gp.fit(X, y)

# Plot posterior
plt.subplot(2, 1, 2)
X_ = np.linspace(0, 5, 100)
y_mean, y_std = gp.predict(X_[:, np.newaxis], return_std=True)
plt.plot(X_, y_mean, 'k', lw=3, zorder=9)
plt.fill_between(X_, y_mean - y_std, y_mean + y_std,
                 alpha=0.2, color='k')

1
这并没有什么实际意义,只是代码作者使用的一些约定。 - Paul Rooney
1个回答

3
这里的下划线似乎只是一个任意变量,不是“适当”使用下划线的方式。 根据Python风格指南
单个下划线结尾:惯例用于避免与Python关键字冲突,例如list_、class_等。通常会看到下划线用于标记某些内容。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接