ValueError: operands could not be broadcast together with shapes (0) (26) when using optimize.curve

北战南征 提交于 2019-12-04 04:28:33

问题


I'm trying to get a best fit line to some data my script generates. This is what I have:

import numpy as np
import scipy as sp
.
.
.
def func(x, a, b, c):
    return a*np.exp(-b*x) + c
popt, pcov = sp.optimize.curve_fit(func, numgelt, turnsG)

I keep getting this error:

ValueError: operands could not be broadcast together with shapes (0) (26)

I have checked and the two arrays (numgelt and turnsG) are definitely the same size. I've also ensured that the entries are float. Thank you!


回答1:


I had the same problem until I realized I had been using lists instead of Numpy arrays. Converting to arrays fixed it for me.




回答2:


ValueError: operands could not be broadcast together with shapes (0) (26)

implies that first of your arrays is of length 0. From your post it is most obviously the case and the error provoking ValueError.



来源:https://stackoverflow.com/questions/16220425/valueerror-operands-could-not-be-broadcast-together-with-shapes-0-26-when-u

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!