I was testing following code in python script user model
importnumpyasnpfromscipy.optimizeimportcurve_fit# Define the function to fitdeffunc(x,a,b,c):#import numpy as npreturna*np.exp(-b*x)+c# Generate sample datax_data=np.linspace(0,4,50)y_data=func(x_data,2.5,1.3,0.5)+0.2*np.random.normal(size=len(x_data))# Fit the datainitial_guess=[1,1,1]# Initial parameter guessparams,_=curve_fit(func,x_data,y_data,initial_guess)# Print the estimated parametersFlowsheet.WriteMessage(str(params[0]))Flowsheet.WriteMessage(str(params[1]))Flowsheet.WriteMessage(str(params[2]))
In function definition func is not able to access numpy library which is imported at top. If I am explicitly importing library inside the function the code works. I have faced similar issue when I was trying to use a function inside another function.
Overall it seems that in python.Net we are not able to access global functions, variables and libraries inside functions. Any thoughts on this???
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I was testing following code in python script user model
In function definition func is not able to access numpy library which is imported at top. If I am explicitly importing library inside the function the code works. I have faced similar issue when I was trying to use a function inside another function.
Overall it seems that in python.Net we are not able to access global functions, variables and libraries inside functions. Any thoughts on this???
try this: