-
-
Notifications
You must be signed in to change notification settings - Fork 11.1k
Closed
Description
The casting of a ctypes
Structure object array to numpy array usually results with a numpy structured array. But if the Structure contains a c_wchar
array (string) field it becomes an object. I could not find the reason why this is happening.
Example:
import numpy as np
import ctypes
class A(ctypes.Structure):
_fields_ = [('s', ctypes.c_wchar * 5)]
np.array((A*2)())
# array([<__main__.A object at 0x7fa99678f9d8>,
# <__main__.A object at 0x7fa98804f1e0>], dtype=object)
While:
class B(ctypes.Structure):
_fields_ = [('s', ctypes.c_char * 5)]
np.array((B*2)())
# array([([b'', b'', b'', b'', b''],), ([b'', b'', b'', b'', b''],)],
# dtype=[('s', 'S1', (5,))])
Environment:
Python 3.6, numpy 1.13.1, Ubuntu 16.04
Metadata
Metadata
Assignees
Labels
No labels