I am using a python wrapper to call functions of a c++ dll library. A ctype is returned by the dll library, which I convert to numpy array
score = np.ctypeslib.as_array(score,1)
however, the array has no shape?
score
>>> array(-0.019486344729027664)
score.shape
>>> ()
score[0]
>>> IndexError: too many indices for array
How can I extract a double from the score array?
Thank you.
()
, aka 0-dimensional. – Kionafloat(score)
. But how are you ending up with a 0-d array, i.e. what's the initial type and value ofscore
? – Occidentnp.ctypeslib.as_array
on this thing?1
isn't a valid shape, and if there's only one value, why do you want to usenp.ctypeslib.as_array
to retrieve it? Why not go through the normal ctypes interface? – Kionashape
parameter is only used for a pointer, so we knowscore
isn't initially a pointer, else passingshape=1
would be an error. If you passas_array
a scalar such asc_double(-0.19)
, it stores an__array_interface__
property on thec_double
type withshape=()
. However, in NumPy 1.8.2 this actually creates an array withshape=(1,)
. Maybe in older versions it creates a scalar 'array'. – Occident