【发布时间】:2015-10-12 13:07:45
【问题描述】:
我想用 C++ 编写一些代码,将向量返回给 python。我尝试了以下示例,但它返回了以下对象。
<Swig Object of type 'std::vector< float > *' at 0x100331f90>
如何将其转换为列表以便在 python 中使用?
我的代码:
/* File: example.i */
%module example
%{
#define SWIG_FILE_WITH_INIT
#include "example.h"
%}
std::vector<float> Test(int n);
.
/* File: example.cpp */
#include <vector>
std::vector<float> Test(int n){
std::vector<float> a(4);
a[1] = 1;
a[2] = 24234;
return a;
}
.
/* File: example.h
http://www.swig.org/Doc1.3/Python.html#Python_nn4
*/
#include <vector>
std::vector<float> Test(int n);
【问题讨论】:
-
我没有用过python,但是尝试在接口文件中添加
%include <std_vector.i> -
谢谢,我试过了,但没有任何改变。