Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/357.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Numpy NDPointer:Don';我不知道如何转换参数1_Python_C++_Numpy - Fatal编程技术网

Python Numpy NDPointer:Don';我不知道如何转换参数1

Python Numpy NDPointer:Don';我不知道如何转换参数1,python,c++,numpy,Python,C++,Numpy,我试图把一个麻木数组推到C++代码中。 < C++函数是, extern "C" void propagate(float * __restrict__ H, const float * __restrict__ W, const float * __restrict__ U, const float * __restrict__ x, float a, int h_len, int samples); 我的python代码是 fro

我试图把一个麻木数组推到C++代码中。 < C++函数是,

extern "C"
void propagate(float * __restrict__ H, const float * __restrict__ W,
               const float * __restrict__ U, const float * __restrict__ x,
               float a, int h_len, int samples);
我的python代码是

from numpy import *
from numpy.ctypeslib import ndpointer
import ctypes

lib = ctypes.cdll.LoadLibrary("libesn.so")

propagate = lib.propagate
propagate.restype = None
propagate.argtype = [ndpointer(ctypes.c_float, flags="C_CONTIGUOUS"),
                     ndpointer(ctypes.c_float, flags="C_CONTIGUOUS"),
                     ndpointer(ctypes.c_float, flags="C_CONTIGUOUS"),
                     ndpointer(ctypes.c_float, flags="C_CONTIGUOUS"),
                     ctypes.c_float, ctypes.c_int, ctypes.c_int]

H = W = U = X = zeros((10, 10))
a = 5.0
propagate(H, W, U, X, a, U.shape[0], X.shape[0])
我犯了一个错误

Traceback (most recent call last):
  File "./minimal.py", line 23, in <module>
    propagate(H, W, U, X, a, U.shape[0], X.shape[0])
ctypes.ArgumentError: argument 1: <type 'exceptions.TypeError'>: Don't know how to convert parameter 1
回溯(最近一次呼叫最后一次):
文件“/minimal.py”,第23行,在
传播(H,W,U,X,a,U.shape[0],X.shape[0])
ctypes.ArgumentError:参数1::不知道如何转换参数1

如何修复此问题?

愚蠢的打字错误。。。应该是
propagate.argtypes
。这修复了导致StackOverflow上已有答案的其他错误的神秘错误

propagate = lib.propagate
propagate.restype = None
propagate.argtypes = [ndpointer(ctypes.c_float, flags="C_CONTIGUOUS"),
                      ndpointer(ctypes.c_float, flags="C_CONTIGUOUS"),
                      ndpointer(ctypes.c_float, flags="C_CONTIGUOUS"),
                      ndpointer(ctypes.c_float, flags="C_CONTIGUOUS"),
                      ctypes.c_float, ctypes.c_int, ctypes.c_int]