问题
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