【发布时间】:2020-09-11 08:16:34
【问题描述】:
我有两个变量 W1、W2 和输出 z = F(W1,W2) 的损失函数。
现在我绘制这个损失函数的等高线图。现在说,我已经计算了两个点的梯度向量,因此我现在有两个梯度向量。我想在我的等高线图上绘制这些梯度向量,但我不知道如何处理。任何帮助表示赞赏
enter code here
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
feature_x = np.arange(-50, 50, 2)
feature_y = np.arange(-50, 50, 3)
# Creating 2-D grid of features
[X, Y] = np.meshgrid(feature_x, feature_y)
fig, ax = plt.subplots(1, 1)
z = 0.5*np.array((Y-X)*(Y-X) + 0.5*(1-X)*(1-X))
# plots contour lines
ax.contour(X, Y, z, 10, cmap = 'jet')
ax.grid(True)
ax.axis('scaled')
#ax.clabel(cp, inline=1, fontsize=10)
ax.set_title('Contour Plot')
ax.set_xlabel('feature_x')
ax.set_ylabel('feature_y')
plt.show()
【问题讨论】:
标签: python matplotlib gradient contour