Extending using Numeric, a quest for patterns
Konrad Hinsen
hinsen at cnrs-orleans.fr
Mon Mar 19 04:49:37 EST 2001
"Greg Landrum" <gReGlAnDrUm at earthlink.net> writes:
> The core of the Python for the bit I'm interested in converting is:
> posArray = array(pos1+pos2)
> avgVect = sum(posArray)/len(posArray)
> devs = posArray-avgVect
> devs *= devs
> e = sum(sum(devs))
> where pos1 and pos2 are python lists.
Keep the first line in Python, there is nothing to gain by converting
it to C. The rest then becomes a single C function which takes
avgVect as input and returns e. But don't expect miracles, unless
your array is rather short, the above Python code should be quite
efficient already.
> What I think would make a lot of this easier is if I could figure out how to
> use the ufuncs from C code. I pored over the source and the docs, but I was
That's not worth the effort, and you'd build in unnecessary overhead.
Just access the array data directly and do your rather simple
calculations in straightforward C code.
Konrad.
--
-------------------------------------------------------------------------------
Konrad Hinsen | E-Mail: hinsen at cnrs-orleans.fr
Centre de Biophysique Moleculaire (CNRS) | Tel.: +33-2.38.25.56.24
Rue Charles Sadron | Fax: +33-2.38.63.15.17
45071 Orleans Cedex 2 | Deutsch/Esperanto/English/
France | Nederlands/Francais
-------------------------------------------------------------------------------
More information about the Python-list
mailing list