[Numpy-discussion] 32/64-bit machines, integer arrays and python ints
oliphant at ee.byu.edu
Thu Sep 28 20:22:24 CDT 2006
Bill Spotz wrote:
>On Sep 28, 2006, at 12:03 PM, Travis Oliphant wrote:
>>The other option is to improve your converter in setElements so
>>can understand any of the array scalar integers and not just the
>I think this may be the best approach.
>This may be something worthwhile to put in the numpy.i interface
>file: a set of typemaps that handle a set of basic conversions for
>those array scalar types for which it makes sense. I'll look into it.
That's a good idea. Notice that there are some routines for making
your life easier here.
You should look at the tp_int function for the gentype array (it
converts scalars to arrays). You call the "__int__" special method of
the scalar to convert it to a Python integer. You should first check to
see that it is an integer scalar PyArray_IsScalar(obj, Integer) because
the "__int__" method coerces to an integer if it is a float (but maybe
you want that behavior).
There are other functions in the C-API that return the data directly
from the scalar --- check them out. The macros in arrayscalar.h are
More information about the Numpy-discussion