def linearize(p, x):
return p[0] * x**p[1]
def error(p, x, y):
return (np.log10(y) - np.log10(linearize(p, x)))
from scipy import optimize
args = freq_log[1:9063], np.abs(spec_log[1:9063])
qout, success = optimize.leastsq(error,
[1e5,-0.8],
args=args,
maxfev=3000)
fig,ax1=plt.subplots(figsize=(5,5))
spec = ax1.plot(freq_log,np.abs(spec_log), 'o', alpha=0.3)
approx = ax1.plot(freq_log[1:], linearize(qout, freq_log[1:]), linewidth=3)
I am trying to replicate a code, and I am trying to understand what linearize does in this case, what arguments it takes, and what the return does in order to remedy the following errors
Currently it returns runtime errors and a ValueError
RuntimeWarning: divide by zero encountered in power return p[0] * x**p[1]
RuntimeWarning: invalid value encountered in power return p[0] * x**p[1]
ValueError: object too deep for desired array
My primary concern is the first four lines, can anyone help me understand what is causing this error and how to remedy it?
Full code is @ https://github.com/seg/tutorials-2017/blob/master/1710_Colored_inversion/Colored_inversion_notebook.ipynb