This is a pre-release version (latest). Go to latest (2.4.4)
{ } Raw JSON

bundles / numpy latest / numpy / ctypeslib / as_ctypes_type

function

numpy.ctypeslib:as_ctypes_type

source: build-install/usr/lib/python3.14/site-packages/numpy/ctypeslib/_ctypeslib.py :463

Signature

def   as_ctypes_type ( dtype )

Summary

Convert a dtype into a ctypes type.

Parameters

dtype : dtype

The dtype to convert

Returns

: ctype

A ctype scalar, union, array, or struct

Raises

: NotImplementedError

If 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)
ctype
Converting a structured dtype:
dt = np.dtype([('x', 'i4'), ('y', 'f4')])
ctype = np.ctypeslib.as_ctypes_type(dt)
ctype

Aliases

  • numpy.ctypeslib.as_ctypes_type

Referenced by