'How to use scipy.optimize.curve_fit for a specific positioned value in a 2D array
I still feel new to python and hope someone understands my problem and can help me out.
So, I have a function dependent on 2 variables which should create a 2D-array inside this function.
Then I want the curve_fit to optimize those two variables, to fit for a single value inside the array on a specified position and then to call the function with the fitted variables.
Right now I cannot call the curve_fit like I want to, because the array position cannot be called from outside the function.
T_aim=175
guess=[0.1, 100]
def function (A,B):
2Darray=np.zeros([100,100])
f=0
for X in linspace(0:100):
g=0
for Z in linspace(0:100):
if(m.sqrt(X**2+Z**2)<=50):
T=0
else:
T=(V*qmax*m.sin(kappa(z))/m.sin(kappa(ap)))*m.exp((-vf*(X-r(z)))/(2*alpha))
2Darray[g,f]=T
g=g+1
f=f+1
fig=plt.figure()
plt.imshow(2Darray)
optpar1,optpar2=curve_fit(function,T_aim,2Darray[45][60],guess)
function(optpar1,optpar2)
the code is simplified, but should at least structurally reflect my code and the desired outcome.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
