2

I have done this function that uses ctypes to create an object with a buffer protocol that points to a specified address:

import numpy as np

def np_buffer_from_address(shape, dtype, address):
    import ctypes
    return np.ndarray(shape, dtype = dtype, buffer = ctypes.c_void_p.from_address(address))

But I wanted to know if I can do this without using ctypes. If you can do it directly with numpy

2

1 Answer 1

2

You can avoid ctypes by using just the standardized __array_interface__, here's an example how it works: Creating a NumPy array directly from __array_interface__ (in fact, numpy.ctypeslib.as_array does the same under the hood, setting typestr and data appropriately)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.