如何获取C的numpy数组的内存地址 [英] how to get the memory address of a numpy array for C
本文介绍了如何获取C的numpy数组的内存地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我构造了一个numpy数组:
I constructed an numpy array::
a=np.ndarray([2,3])
那我想看看它的数据在哪里:
then i want to see where its data are::
a.data
>>>Out[213]: <read-write buffer for 0x0482C1D0, size 48, offset 0 at 0x049E87A0>
a.data
>>>Out[214]: <read-write buffer for 0x0482C1D0, size 48, offset 0 at 0x049E82A0>
a.data
>>>Out[215]: <read-write buffer for 0x0482C1D0, size 48, offset 0 at 0x049E81C0>
...
为什么每次偏移地址都不相同? 如果我想通过以下方式使用c_types将数据传输到c函数:
why every time the offset address is different? if i want to transfer the data to a c function using c_types by::
ctypes_array = (ctypes.c_char * a.size * 8).from_address(ptr)
我应该如何获得ptr的价值?
how should i get the value of ptr?
推荐答案
此外,请查看 ndarray.__array_interface__
,这是一个字典,其中包含您要获取的所有信息.
Also, have a look at ndarray.__array_interface__
, which is a dict that contains all of the information you're after.
就您而言,
pointer, read_only_flag = a.__array_interface__['data']
这篇关于如何获取C的numpy数组的内存地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文