[英]contour plot with python loop and matplotlib
我无法弄清楚是什么导致我无法获得此成本函数的轮廓图。 经过反复尝试和错误,我得到:
ValueError: zero-size array to reduction operation minimum which has no identity
如果我打印J,它不会给我任何值,而只是一个100x100的数组,数组中包含nan。 那是原因吗? J应该充满成本值,对吗? 非常感谢您的帮助。
X,y,ComputeCost = defined earlier and 90% sure not the problem
theta_zero = np.linspace(-10,10,100)
theta_one = np.linspace(-1,4,100)
L,Q = np.meshgrid(theta_zero,theta_one)
J = np.zeros((len(theta_zero),len(theta_one)))
for i in range(0,len(theta_zero)):
for j in range(0,len(theta_one)):
t = DataFrame([theta_zero[i],theta_one[j]])
J[i,j] = ComputeCost(X,y,t)
plt.contour(L,Q,J)
如果J
只是nan
s,那么问题就在于生成J
的方式,而不是 contour()
调用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.