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.float(score). But how are you ending up with a 0-d array, i.e. what's the initial type and value ofscore?np.ctypeslib.as_arrayon this thing?1isn't a valid shape, and if there's only one value, why do you want to usenp.ctypeslib.as_arrayto retrieve it? Why not go through the normal ctypes interface?shapeparameter is only used for a pointer, so we knowscoreisn't initially a pointer, else passingshape=1would be an error. If you passas_arraya scalar such asc_double(-0.19), it stores an__array_interface__property on thec_doubletype withshape=(). However, in NumPy 1.8.2 this actually creates an array withshape=(1,). Maybe in older versions it creates a scalar 'array'.