【问题标题】:Pass simple numpy array to C via SWIG通过 SWIG 将简单的 numpy 数组传递给 C
【发布时间】:2012-01-12 09:30:28
【问题描述】:

我想通过 SWIG 将已知大小和类型的 numpy 数组传递给 C 函数

# .py
data = numpy.arange( N , dtype=numpy.int32 )
external_c_function( data )

# .i
extern void external_c_function( int32_t* data );

# .c
void external_c_function( int32_t* data)
{
    // ...
}

不幸的是,我会得到一个错误:

TypeError: in method 'external_c_function', argument 1 of type 'int32_t *'

将 numpy 数组传递给 SWIG 的最简单方法是什么?

【问题讨论】:

    标签: python c numpy swig


    【解决方案1】:

    您可以使用numpy.i。看看http://www.scipy.org/Cookbook/SWIG_NumPy_examples

    【讨论】:

      猜你喜欢
      • 2016-10-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多