8000 DOC: add examples to ctypeslib by m-clare · Pull Request #27598 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

DOC: add examples to ctypeslib #27598

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 19, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
DOC: examples [skip azp] [skip actions] [skip cirrus]
Add additional method test on ctype conversion
  • Loading branch information
m-clare committed Oct 19, 2024
commit ce75474397238958c28f70b1a8a8eb3af3ec229d
12 changes: 8 additions & 4 deletions numpy/ctypeslib.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,15 +571,19 @@ def as_ctypes(obj):

>>> inferred_int_array = np.array([1, 2, 3])
>>> c_int_array = np.ctypeslib.as_ctypes(inferred_int_array)
>>> c_int_array
<c_long_Array_3 at 0x1071fbed0>
>>> type(c_int_array)
<class 'c_long_Array_3'>
>>> c_int_array[:]
[1, 2, 3]

Create ctypes object from explicit 8 bit unsigned int ``np.array`` :

>>> exp_int_array = np.array([1, 2, 3], dtype=np.uint8)
>>> c_int_array = np.ctypeslib.as_ctypes(exp_int_array)
>>> c_int_array
<c_ubyte_Array_3 at 0x10755a950>
>>> type(c_int_array)
<class 'c_ubyte_Array_3'>
>>> c_int_array[:]
[1, 2, 3]

"""
ai = obj.__array_interface__
Expand Down
0