Jul-13-2020, 10:44 AM
Hey! I need help developing a code for a multi-gaussian function. The point would be to create a function that uses the number of gaussian requested by the user to make the final fitting function. All parameters are passed as *params and number of gaussians is deduced from the number of items in *params (1 + n*3). However, I am very new to coding and was left with a base to work with, only I am confused of what to do next.
This is the code so far:
I understand that n_gauss should be extracted from the length of *params, but I am unsure of how the parameters should be defined: in the file that I use the function in, or in this same code, such as here
This is the code so far:
def multi_gaussian(x, *params): y0 = params[0] n_gauss = ... y = np.ones_like() for i in range(n_gauss): parameters = ... y += gaussian(x, parameters) return y
I understand that n_gauss should be extracted from the length of *params, but I am unsure of how the parameters should be defined: in the file that I use the function in, or in this same code, such as here
def two_gaussian(x, *param): y0, A1, w1, xc1, A2, w2, xc2 = param y = y0 + (A1/(w1*np.sqrt(np.pi/2)))*np.exp(-2*np.power((x-xc1)/w1, 2.)) + (A2/(w2*np.sqrt(np.pi/2)))*np.exp(-2*np.power((x-xc2)/w2, 2.)) return yy should be a constant background function, but I am unsure of how extracting parameters works. Any kind of help is appreciated!