Python 数组名称下划线含义
我对下面的示例代码有一个问题。我确信传递给gp.predict的值是Python 数组名称下划线含义,python,python-3.x,gaussian,Python,Python 3.x,Gaussian,我对下面的示例代码有一个问题。我确信传递给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.
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')
这不是尾随下划线的“正确”用法。这似乎只是一个任意变量
:
单\尾随\下划线\按惯例使用,以避免与Python关键字冲突,例如
您经常会看到一个尾随下划线,用于标记
列表
,或类
,等等。它没有任何意义。这是本代码作者使用的一些惯例。如果答案解决了您的问题,请接受它-请参阅