bundles / numpy 2.4.4 / numpy / ctypeslib / as_ctypes_type
function
numpy.ctypeslib:as_ctypes_type
Signature
def as_ctypes_type ( dtype ) Summary
Convert a dtype into a ctypes type.
Parameters
dtype: dtypeThe dtype to convert
Returns
: ctypeA ctype scalar, union, array, or struct
Raises
: NotImplementedErrorIf the conversion is not possible
Notes
This function does not losslessly round-trip in either direction.
np.dtype(as_ctypes_type(dt)) will:
insert padding fields
reorder fields to be sorted by offset
discard field titles
as_ctypes_type(np.dtype(ctype)) will:
discard the class names of ctypes.Structures and ctypes.Unions
convert single-element ctypes.Unions into single-element ctypes.Structures
insert padding fields
Examples
Converting a simple dtype:dt = np.dtype('int8') ctype = np.ctypeslib.as_ctypes_type(dt) ctypeConverting a structured dtype:
dt = np.dtype([('x', 'i4'), ('y', 'f4')]) ctype = np.ctypeslib.as_ctypes_type(dt) ctype
Aliases
-
numpy.ctypeslib.as_ctypes_type