Python 如何用DLL中的C函数填充numpy数组?
我有一个用C编写的DLL:Python 如何用DLL中的C函数填充numpy数组?,python,numpy,dll,ctypes,Python,Numpy,Dll,Ctypes,我有一个用C编写的DLL: void fill(int* a) { a[0] = 2; a[1] = 3; a[2] = 5; } 我想做的是创建一个numpy数组,其中包含写入a的数字 我试过这个: import ctypes _dll = ctypes.CDLL("mydll.so") type_ = np.int32 bf = ctypes.create_string_buffer(3 * np.dtype(type_).itemsize) _dll.fil
void fill(int* a) {
a[0] = 2;
a[1] = 3;
a[2] = 5;
}
我想做的是创建一个numpy数组,其中包含写入a
的数字
我试过这个:
import ctypes
_dll = ctypes.CDLL("mydll.so")
type_ = np.int32
bf = ctypes.create_string_buffer(3 * np.dtype(type_).itemsize)
_dll.fill(bf)
a = np.frombuffer(bf.value, dtype=type_)
print(a)
它给出了错误:
a = np.frombuffer(bf.value, dtype=type_)
ValueError: buffer size must be a multiple of element size
我的python代码有什么问题