本文介绍了ValueError:使用optimize.curve时,操作数不能与形状(0)(26)一起广播的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正试图为我的脚本生成的某些数据找到最合适的界线。这就是我所拥有的:
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)
我一直收到此错误:
ValueError: operands could not be broadcast together with shapes (0) (26)
$ b $一起广播b
我检查了两个数组(numgelt和turnsG)的大小肯定相同。我还确保了条目是浮动的。谢谢!
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!
推荐答案
我遇到了同样的问题,直到我意识到我一直在使用列表而不是Numpy数组。转换为数组对我来说已经解决了。
I had the same problem until I realized I had been using lists instead of Numpy arrays. Converting to arrays fixed it for me.
这篇关于ValueError:使用optimize.curve时,操作数不能与形状(0)(26)一起广播的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!