[Numpy-discussion] 32/64-bit machines, integer arrays and python ints
wfspotz at sandia.gov
Thu Sep 28 11:43:26 CDT 2006
I am wrapping code using swig and extending it to use numpy.
One class method I wrap (let's call it myElements()) returns an array
of ints, and I convert it to a numpy array with
I obtain the data pointer, fill in the values and return it as the
method return argument.
In python, it is common to want to loop over this array and treat its
elements as integers:
for row in map.myElements():
matrix.setElements(row, [row-1,row,row+1], [-1.0,2.0,-1.0])
On a 32-bit machine, this has worked fine, but on a 64-bit machine, I
get a type error:
TypeError: in method 'setElements', argument 2 of type 'int'
because row is a <type 'int32scalar'>.
It would be nice if I could get the integer conversion to work
automatically under the covers, but I'm not exactly sure how to make
** Bill Spotz **
** Sandia National Laboratories Voice: (505)845-0170 **
** P.O. Box 5800 Fax: (505)284-5451 **
** Albuquerque, NM 87185-0370 Email: wfspotz at sandia.gov **
More information about the Numpy-discussion