Fitting a 2D Gaussian function using scipy.optimize.curve_fit – ValueError and minpack.error

The output of twoD_Gaussian needs to be 1D. What you can do is add a .ravel() onto the end of the last line, like this: def twoD_Gaussian(xy, amplitude, xo, yo, sigma_x, sigma_y, theta, offset): x, y = xy xo = float(xo) yo = float(yo) a = (np.cos(theta)**2)/(2*sigma_x**2) + (np.sin(theta)**2)/(2*sigma_y**2) b = -(np.sin(2*theta))/(4*sigma_x**2) + (np.sin(2*theta))/(4*sigma_y**2) c … Read more

Fitting a closed curve to a set of points

Actually, you were not far from the solution in your question. Using scipy.interpolate.splprep for parametric B-spline interpolation would be the simplest approach. It also natively supports closed curves, if you provide the per=1 parameter, import numpy as np from scipy.interpolate import splprep, splev import matplotlib.pyplot as plt # define pts from the question tck, u … Read more

How to find probability distribution and parameters for real data? (Python 3)

Use this approach import scipy.stats as st def get_best_distribution(data): dist_names = [“norm”, “exponweib”, “weibull_max”, “weibull_min”, “pareto”, “genextreme”] dist_results = [] params = {} for dist_name in dist_names: dist = getattr(st, dist_name) param = dist.fit(data) params[dist_name] = param # Applying the Kolmogorov-Smirnov test D, p = st.kstest(data, dist_name, args=param) print(“p value for “+dist_name+” = “+str(p)) dist_results.append((dist_name, … Read more

fitting data with numpy

Unfortunately, np.polynomial.polynomial.polyfit returns the coefficients in the opposite order of that for np.polyfit and np.polyval (or, as you used np.poly1d). To illustrate: In [40]: np.polynomial.polynomial.polyfit(x, y, 4) Out[40]: array([ 84.29340848, -100.53595376, 44.83281408, -8.85931101, 0.65459882]) In [41]: np.polyfit(x, y, 4) Out[41]: array([ 0.65459882, -8.859311 , 44.83281407, -100.53595375, 84.29340846]) In general: np.polynomial.polynomial.polyfit returns coefficients [A, B, C] … Read more

Meaning of validation_steps in Keras Sequential fit_generator parameter list

The validation generator works exactly like the training generator. You define how many batches it will wield per epoch. The training generator will yield steps_per_epoch batches. When the epoch ends, the validation generator will yield validation_steps batches. But validation data has absolutely no relation to training data. There is no need to separate validation batches … Read more