簡體   English   中英

帶有python循環和matplotlib的輪廓圖

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM