[Numpy-discussion] scipy curve_fit variable list of optimisation parameters

Siegfried Gonzi siegfried.gonzi at ed.ac.uk
Tue Aug 2 13:41:21 EDT 2016

Hi all

Does anyone know how to invoke curve_fit with a variable number of parameters, e.g. a1 to a10 without writing it out,


def func2( x, a1,a2,a3,a4 ):

        # Bessel function
	tmp = scipy.special.j0( x[:,:] )

	return np.dot( tmp[:,:] , np.array( [a1,a2,a3,a4] )

### yi = M measurements (.e.g M=20)
### x = M (=20) rows of N (=4) columns
popt = scipy.optimize.curve_fit( func2, x, yi )

I'd like to get *1 single vector* (in this case of size 4) of optimised A(i) values.

The function I am trying to minimise (.e.g F(r) is a vector of 20 model measurements): F(r) = SUM_i_to_N [ A(i) * bessel_function_J0(i * r) ] 

Siegfried Gonzi

The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.

More information about the NumPy-Discussion mailing list