[SciPy-user] Best/Safest way to parse NumPy array in C extension?
lou_boog2000 at yahoo.com
Tue Dec 12 10:24:13 CST 2006
I've done this two ways. Which is better or safer?
Say I'm passing a NumPy array (float) to a C
extension. One way to "parse" it is (ignoring checks
on return values, etc. for now),
PyArg_ParseTuple(args, "O!", &PyArray_Type, &mat);
or is this better,
PyArg_ParseTuple(args, "O", &Pymat);
The latter appears to have the constraint that the
array be contiguous. Or is that an illusion and it's
saying it _expects_ a Python object that has
I've done both. Pointing C arrays to the resulting
PyArrays' data works fine, but I fear one way or the
other might be courting disaster.
BTW, I do other checks on dimension, type, etc., but I
left those out here for clarity. (I hope.)
-- Lou Pecora
My views are my own.
Do you Yahoo!?
Everyone is raving about the all-new Yahoo! Mail beta.
More information about the SciPy-user