Seite 1 von 1

Scipy: cant multiply sequence by non-int ...

Verfasst: Donnerstag 23. Juli 2020, 11:36
von naheliegend
Hi,

er schmeißt mir den Fehler:
Traceback (most recent call last):
File "..." line 30, in <module>
plt.plot(x_d, exponential(x_d, pars[0], pars[1]), linestyle='--', linewidth=2, color='black')
File "...", line 9, in exponential
return a*np.exp(b*x)
TypeError: can't multiply sequence by non-int of type 'numpy.float64'

Code: Alles auswählen

def exponential(x, a, b):
    return a*np.exp(b*x)


pars, cov = curve_fit(f=exponential, xdata=x_d, ydata=y, p0=[0.1, 0.1], maxfev=1000)

plt.plot(x_d, exponential(x_d, pars[0], pars[1]), linestyle='--', linewidth=2, color='black')
Was mache ich falsch?

Re: Scipy: cant multiply sequence by non-int ...

Verfasst: Donnerstag 23. Juli 2020, 12:11
von Sirius3
Dann finde mal heraus, welche Deiner drei Variablen x, a oder b eine Sequenz ist und was dessen Inhalt ist (print könnte dabei hilfreich sein).

Re: Scipy: cant multiply sequence by non-int ...

Verfasst: Donnerstag 23. Juli 2020, 13:08
von NPC
Naja also a und b sind durch den curve_fit ja type float. Daher ist das eigentlich kein Problem. Solange x_d ein np.array() ist sollte die multiplikation mit einem Scalar definiert sein und damit das argument der exp eigentlich ein np.array zurück liefern. Wenn a wieder ein parameter ist, dass passt es eigentlich. D.h. ich vermute, dass du x_d nicht als np array definiert ist, was im plot(..., exponential(...)) dann zu einem Fehler führt. Aber ohne etwas mehr Informationen ist das schwer abzuschätzen.