Friday, 15 January 2010

python - How to get values from PyArrayObject? -



python - How to get values from PyArrayObject? -

i seek values list. it's defined in python as:

line1 = [[[146.0, 560.0], [337.0, 478.0]], [[204.0, 612.0], [397.0, 536.0]], [[166.0, 437.0], [350.0, 434.0]], [[166.0, 552.0], [350.0, 546.0]], [[146.0, 560.0], [337.0, 478.0]], [[204.0, 612.0], [397.0, 536.0]], [[166.0, 437.0], [350.0, 434.0]], [[166.0, 552.0], [350.0, 546.0]]]

parsed pyarrayobject by:

pyarrayobject *linea = (pyarrayobject*) pyarray_fromany (objlinea, pyarray_double, 3, 3, npy_in_array); if (!linea) { pyerr_setstring(pyexc_valueerror, "expected [layer][point][x] "); homecoming null; }

till seems ok, dimensions ok. when im trying:

struct ppoint { float x; float y; }; ... struct ppoint p1a, p1b; ... p1a.x = *((float * )pyarray_getptr3(linea, 0, 0, 0)); p1a.y = *((float * )pyarray_getptr3(linea, 0, 0, 1)); p1b.x = *((float * )pyarray_getptr3(linea, 0, 1, 0)); p1b.y = *((float * )pyarray_getptr3(linea, 0, 1, 1)); ...

all values zero.

what best , easiest way values pyobjarray? why 0.0?

i met same problem. when print out value, 0.0. seek alter 'float' 'double' in c. float type in python double type in c. claimed type pyarray_double.

python c numpy

No comments:

Post a Comment