Thanks to visit codestin.com
Credit goes to github.com

Skip to content

np.ctypeslib.as_array(struct_array) gives an unstructured void array #10978

Closed
@eric-wieser

Description

@eric-wieser
>>> class Struct(ctypes.Structure):
...     fields = [('a', ctypes.c_int16)]

>>> arr = (Struct*3)()

>>> np.ctypeslib.as_array(arr)
AttributeError: 'Struct' object has no attribute '__array_interface__'
# hmm

>>> pointer = ctypes.pointer(arr[0])
>>> np.ctypeslib.as_array(pointer, shape=(3,))
array([None, None, None], dtype=object)
# wat

>>> pointer_all = ctypes.pointer(arr)
>>> np.ctypeslib.as_array(pointer_all, shape=())
array(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', 
      dtype='|V24')
# wat

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions