8000 Merge pull request #26827 from otieno-juma/ai-examples-ctypeslib-as-c… · numpy/numpy@c8ed7e9 · GitHub
[go: up one dir, main page]

Skip to content

Commit c8ed7e9

Browse files
authored
Merge pull request #26827 from otieno-juma/ai-examples-ctypeslib-as-ctypes
DOC: AI-Gen examples ctypeslib.as_ctypes_types
2 parents bfaef9c + 0d8832e commit c8ed7e9

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

numpy/ctypeslib.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,22 @@ def as_ctypes_type(dtype):
499499
`ctypes.Structure`\ s
500500
- insert padding fields
501501
502+
Examples
503+
--------
504+
Converting a simple dtype:
505+
506+
>>> dt = np.dtype('i4')
507+
>>> ctype = np.ctypeslib.as_ctypes_type(dt)
508+
>>> ctype
509+
<class 'ctypes.c_int32'>
510+
511+
Converting a structured dtype:
512+
513+
>>> dt = np.dtype([('x', 'i4'), ('y', 'f4')])
514+
>>> ctype = np.ctypeslib.as_ctypes_type(dt)
515+
>>> ctype
516+
<class 'ctypes.Structure'>
517+
502518
"""
503519
return _ctype_from_dtype(_dtype(dtype))
504520

0 commit comments

Comments
 (0)
0