I'm porting a C++
algorithm to Python
. All has gone well so far (it translated pretty much verbatim, or as least as nearly as a c++
to Python
translation could hope to be), all I have left to do is this piece:
int N=6;
Approximate ax,ay;
double e,dt[n];
for (ax.init( 0.0,512.0, 32.0 ,N, &e);!ax.done;ax.step())
for (ay.init( 0.0,512.0, 32.0 ,N, &e);!ay.done;ay.step())
{
for (i=0;i<n;i++){
x=recv[i][0]-ax.a;
y=recv[i][1]-ay.a;
a=sqrt((x*x)+(y*y));
dt[i]=a/v;
}
a=dt[0];
for (i=1;i<n;i++)
if (a>dt[i])
a=dt[i];
for (i=0;i<n;i++)
dt[i]-=a;
e=0.0;
for (i=0;i<n;i++)
e+=fabs(recv[i][2]-dt[i]);
}
pos[0]=ax.aa;
pos[1]=ay.aa;
}
Admittedly, my Python
is a bit rusty. What would be the Python
'equivalent' of these nested loops? It isn't clear to me how this could be done with a Python for
loop. I'm not really sure where to begin.
I haven't included the Approximate
class here as it is rather lengthy and, I think, irrelevant, although I'd be happy to share if that would be useful. Approximate
is an approximation search class. done
is (obviously) a boolean, indicating when a solution has been found and the algorithm should terminate and print the solution, ax.a
and ay.a
(not to be confused with ax.aa
and ay.aa
).
Please let me know if any additional information would be helpful. I'm trying to maintain a balance of providing enough information such that this is a well-defined question, and not so much as to overwhelm the reader where this is (probably) a simple problem.