sto ottenendo il seguente messaggio di avviso quando si tenta di utilizzare un array ctypes come un array NumPy:PEP 3118 avvertimento quando si utilizza ctypes matrice come NumPy serie
Python 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import ctypes, numpy
>>> TenByteBuffer = ctypes.c_ubyte * 10
>>> a = TenByteBuffer()
>>> b = numpy.ctypeslib.as_array(a)
C:\Python27\lib\site-packages\numpy\ctypeslib.py:402: RuntimeWarning: Item size
computed from the PEP 3118 buffer format string does not match the actual item s
ize.
return array(obj, copy=False)
>>> b
array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0], dtype=uint8)
Il codice sembra funzionare, però. È una cattiva idea ignorare questo avvertimento?
Sfondo: Sto chiamando una DLL C che produce dati in tempo reale. Ho bisogno di passare alla DLL una serie di buffer per contenere i dati. Mentre aspetto il prossimo buffer da riempire, mi piacerebbe elaborare il buffer più recente con numpy e salvare il risultato. Sto generando i buffer con il codice come sopra, e le cose sembrano funzionare, ma non voglio spazzare un problema importante sotto il tappeto.
È interessante notare che questo non sembra accadere con python2.6, solo python2.7 ... –