constructing an array from memory
I'm trying to do something ... unusual. gdb support scripting with Python. From within my python script, I can get the address of a contiguous area of memory that stores a fortran array. I want to creat a NumPy array using "frombuffer". I see that the CPython API supports the creation of a buffer, but, is there an easier, more direct, way? -Mathew
I'm trying to do something ... unusual.
gdb support scripting with Python. From within my python script, I can get the address of a contiguous area of memory that stores a fortran array. I want to creat a NumPy array using "frombuffer". I see that the CPython API supports the creation of a buffer, but, is there an easier, more direct, way?
Here's how I do a similar task: numpy.ndarray(shape, dtype=dtype, buffer=(ctypes.c_char*size_in_bytes).from_address(address)) You may need the strides or order parameters, as well. Perhaps there's an easier way to create a buffer from an integer memory address, but this seems pretty straightforward. Zach
Thank a lot. I was wading through the Python C API. This is much simpler.
-Mathew
On Fri, Sep 24, 2010 at 10:21 AM, Zachary Pincus
I'm trying to do something ... unusual.
gdb support scripting with Python. From within my python script, I can get the address of a contiguous area of memory that stores a fortran array. I want to creat a NumPy array using "frombuffer". I see that the CPython API supports the creation of a buffer, but, is there an easier, more direct, way?
Here's how I do a similar task: numpy.ndarray(shape, dtype=dtype, buffer=(ctypes.c_char*size_in_bytes).from_address(address))
You may need the strides or order parameters, as well.
Perhaps there's an easier way to create a buffer from an integer memory address, but this seems pretty straightforward.
Zach _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
On Fri, Sep 24, 2010 at 11:25, Mathew Yeates
I'm trying to do something ... unusual.
gdb support scripting with Python. From within my python script, I can get the address of a contiguous area of memory that stores a fortran array. I want to creat a NumPy array using "frombuffer". I see that the CPython API supports the creation of a buffer, but, is there an easier, more direct, way?
You can also make an object with an .__array_interface__ attribute
describing the data.
[~]
|5> x = np.arange(10)
[~]
|6> x.__array_interface__
{'data': (68583072, False),
'descr': [('', '
participants (3)
-
Mathew Yeates
-
Robert Kern
-
Zachary Pincus