Python + C/C++ 嵌入式编程 (基础)

Python 提供了丰富的 C API 函数,我们使用这些 C API 函数可以实现将 Python 文件中的函数、类等在 C/C++ 文件中进行调用,从而使得我们可以方便地使用 Python 代码来帮助我们实现一些额外的需求(如:嵌入神经网络模型)。

网上已经有很多介绍如何将 Python 嵌入到 C/C++ 的博客,这里不再累述。这里主要叙述一下如何实现多维数组在 Python 文件和 C/C++文件间互传,即如何从 Python 文件中返回 Numpy 数组,已经如何从 C/C++文件中传递一个多维数组到Python文件中。在处理这个的过程中,遇到了许多的困难,查阅了许多网站,发现中文博客中对这部分的相信介绍不是很多,故特此写这篇论文(第一篇博文,不详细的地方望评论中指出,有问题也欢迎在评论中咨询)。

博文目录:

  • 从 Python 文件中的函数返回 List 数组
  • 从 Python 文件中的函数返回包含 Numpy Array 的 List 数组
  • 向 Python 文件中的函数传递 List 数组
  • 向 Python 文件中的函数传递 Numpy Array 数组

从 Python 文件中的函数返回 List 数组:

如果我们在 C/C++ 文件中调用的 Python 函数返回的是 List 数组,那么我们这里主要用到的是 Python C API 中的 List Object 来处理返回的数据,主要用到 List Object 里面的这些函数:

  • int PyList_Check(PyObject *list)函数判断一个 PyObject 指针对象是不是一个 List 对象;
  • Py_ssize_t PyList_Size (PyObject *list) 函数计算一个 List 对象的大小;
  • PyObject* PyList_GetItem(PyObject *list, Py_ssize_t index) 函数返回 List对象中第 index 个元素的 PyObject 指针。

示例:假设我们有这么一个Python函数:

def IntegerListReturn():

    IntegerList = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]

    return IntegerList
  • 1
  • 2
  • 3
  • 4
  • 5

我们在 C/C++ 文件中调用这个 Python 函数时,将返回 List 对象,那么我们将在 C/C++文件中进行如下的接收操作:

 // some code omitted...
 cout<<"Integer List Show:"<<endl;
 PyObject *pFuncTwo     = PyDict_GetItemString(pDict, "IntegerListReturn");
 PyObject *FuncTwoBack  = PyObject_CallObject (pFuncTwo, nullptr);//返回List对象

 if(PyList_Check(FuncTwoBack)){ //检查是否为List对象

     int SizeOfList = PyList_Size(FuncTwoBack);//List对象的大小,这里SizeOfList = 3
     for(Index_i = 0; Index_i < SizeOfList; Index_i++){

         PyObject *ListItem = PyList_GetItem(FuncTwoBack, Index_i);//获取List对象中的每一个元素

         int NumOfItems = PyList_Size(ListItem);//List对象子元素的大小,这里NumOfItems = 3

         for(Index_k = 0; Index_k < NumOfItems; Index_k++){

             PyObject *Item = PyList_GetItem(ListItem, Index_k);//遍历List对象中子元素中的每个元素

             cout << PyInt_AsLong(Item) <<" "; //输出元素

             Py_DECREF(Item); //释放空间
         }

         Py_DECREF(ListItem); //释放空间
     }
     cout<<endl;

 }else{

     cout<<"Not a List"<<endl;
 }
 // some code omitted...
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32

从 Python 文件中的函数返回包含 Numpy Array 的 List 数组

带有 Numpy Array 的 List 数组,除了上述提到的 List Object 操作函数,这里还需要用到 PyArrayObject 这个对象来处理返回的 Numpy Array。先介绍一下PyArrayObject, 这个 C API 模块来自 Numpy Module 中,所以使用这个 C API 模块前需要进行一些初始化操作:

// some code omitted...
#include <numpy/arrayobject.h> //包含 numpy 中的头文件arrayobject.h
using namespace std;

void init_numpy(){//初始化 numpy 执行环境,主要是导入包,python2.7用void返回类型,python3.0以上用int返回类型

    import_array();
}
int main()
{

    Py_Initialize();
    init_numpy();
    // some code omitted...
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

做完初始化后,我们就可以使用 PyArrayObject 对象。先对PyArrayObject 对象做一个简单的介绍。PyArrayObject 实际上是一个结构体,结构体内包含四个元素,用来访问 Numpy Array 中的数据:

  1. int nd:Numpy Array数组的维度。
  2. int *dimensions :Numpy Array 数组每一维度数据的个数。
  3. int *strides:Numpy Array 数组每一维度的步长。
  4. char *data: Numpy Array 中指向数据的头指针。

所以当我们要访问 PyArrayObject 对象中的数据时,有:

 //对于二维 Numpy Array 数组,我们访问[i, j]位置处的元素的值
 PyArrayObject *array
 array->data + i*array->strides[0] + j*array->strides[1]
  • 1
  • 2
  • 3

知道如何访问PyArrayObject对象中的数据后,这里给出简单的示例:

#假设我们有这么一段 python 代码:
def ArrayListReturn():

    ArrList = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]

    Array_A  = np.asarray(ArrList, dtype='float' )
    Array_B  = np.asarray(ArrList, dtype='double')

    return [Array_A, Array_B]
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

那么我们在 C/C++中做如下的访问:

/*Return the List which contains Numpy Array*/
PyObject *pFuncOne    = PyDict_GetItemString(pDict, "ArrayListReturn");

PyObject *FuncOneBack = PyObject_CallObject(pFuncOne, nullptr);

int Index_i = 0, Index_k = 0, Index_m = 0, Index_n = 0;
if(PyList_Check(FuncOneBack)){

    int SizeOfList = PyList_Size(FuncOneBack);

    for(Index_i = 0; Index_i < SizeOfList; Index_i++){

        PyArrayObject *ListItem = (PyArrayObject *)PyList_GetItem(FuncOneBack, Index_i);//读取List中的PyArrayObject对象,这里需要进行强制转换。

        int Rows = ListItem->dimensions[0], columns = ListItem->dimensions[1];
        cout<<"The "<<Index_i<<"th Array is:"<<endl;
        for(Index_m = 0; Index_m < Rows; Index_m++){

            for(Index_n = 0; Index_n < columns; Index_n++){

                cout<<*(double *)(ListItem->data + Index_m * ListItem->strides[0] + Index_n * ListItem->strides[1])<<" ";//访问数据,Index_m 和 Index_n 分别是数组元素的坐标,乘上相应维度的步长,即可以访问数组元素
            }
            cout<<endl;
        }

        Py_DECREF(ListItem);
    }
}else{

    cout<<"Not a List"<<endl;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

向 Python 文件中的函数传递 List 数组

现在我们的需求是我们要将 C/C++文件中的数组传递给 Python 文件的某个函数,那么我们将借助 List Object 和 Tuple Object 来封装我们的数据,从而传递给 Python 文件中的函数。

扫描二维码关注公众号,回复: 25190 查看本文章
#假设现在我们有这样一个Python函数,其功能是接受一个由 C/C++ 文件传递的List数组,并打印出来
def PassListFromCToPython(List):

    PyList = List
    print (PyList)
  • 1
  • 2
  • 3
  • 4
  • 5

那么在 C/C++ 文件端,我们需要做如下处理:

/*Pass by List: Transform an C Array to Python List*/

    double CArray[] = {1.2, 4.5, 6.7, 8.9, 1.5, 0.5};

    PyObject *PyList  = PyList_New(6);//定义一个与数组等长的PyList对象数组
    PyObject *ArgList = PyTuple_New(1);//定义一个Tuple对象,Tuple对象的长度与Python函数参数个数一直,上面Python参数个数为1,所以这里给的长度为1
    for(Index_i = 0; Index_i < PyList_Size(PyList); Index_i++){

        PyList_SetItem(PyList, Index_i, PyFloat_FromDouble(CArray[Index_i]));//给PyList对象的每个元素赋值
    }

    PyObject *pFuncFour = PyDict_GetItemString(pDict, "PassListFromCToPython");
    cout<<"C Array Pass Into The Python List:"<<endl;
    PyTuple_SetItem(ArgList, 0, PyList);//将PyList对象放入PyTuple对象中
    PyObject_CallObject(pFuncFour, ArgList);//调用函数,完成传递
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

向 Python 文件中的函数传递 Numpy Array 数组

当我们需要向 Python 文件中传递一个多维数组时,这个时候我们借助PyArrayObject 和 PyTuple 会更加的合适。

#假设现在我们的Python函数是接受一个 Numpy Array 数组进行处理
def PassArrayFromCToPython(Array):

    print "Shape Of Array:", Array.shape

    print Array
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

那么我们就需要在 C/C++ 文件中做如下的处理:

double CArrays[3][3] = {{1.3, 2.4, 5.6}, {4.5, 7.8, 8.9}, {1.7, 0.4, 0.8}}; //定义一个3 X 3的数组

    npy_intp Dims[2] = {3, 3}; //给定维度信息

    PyObject *PyArray  = PyArray_SimpleNewFromData(2, Dims, NPY_DOUBLE, CArrays); //生成包含这个多维数组的PyObject对象,使用PyArray_SimpleNewFromData函数,第一个参数2表示维度,第二个为维度数组Dims,第三个参数指出数组的类型,第四个参数为数组
    PyObject *ArgArray = PyTuple_New(1);
    PyTuple_SetItem(ArgArray, 0, PyArray); //同样定义大小与Python函数参数个数一致的PyTuple对象

    PyObject *pFuncFive = PyDict_GetItemString(pDict, "PassArrayFromCToPython");
    PyObject_CallObject(pFuncFive, ArgArray);//调用函数,传入Numpy Array 对象。
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

代码块

下面给出完整的代码示例:

#ModuleOne.py文件
def ArrayListReturn():

    ArrList = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]

    Array_A  = np.asarray(ArrList, dtype='float' )
    Array_B  = np.asarray(ArrList, dtype='double')

    return [Array_A, Array_B]

def IntegerListReturn():

    IntegerList = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]

    return IntegerList

def FloatListReturn():

    FloatList = [[1.2, 2.3, 3.5], [0.5, 5.2, 6.5], [7.2, 8.8, 9.3]]

    return FloatList

def PassListFromCToPython(List):

    PyList = List
    print (PyList)

def PassArrayFromCToPython(Array):

    print "Shape Of Array:", Array.shape

    print Array
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32

C/C++文件:

#include <iostream>
#include <Python.h>
#include <numpy/arrayobject.h>
using namespace std;

void init_numpy(){

    import_array();
}
int main()
{

    Py_Initialize();
    init_numpy();

    PyRun_SimpleString("import sys");
    PyRun_SimpleString("sys.path.append('/home/liaojian/Documents/Programming/PythonWorkSpace/CalledByCplusplus/')");

    PyObject *pModule  = nullptr;
    PyObject *pDict    = nullptr;

    pModule  = PyImport_ImportModule("ModuleOne");
    pDict    = PyModule_GetDict(pModule);

    /*Return the List which contains Numpy Array*/
    PyObject *pFuncOne    = PyDict_GetItemString(pDict, "ArrayListReturn");

    PyObject *FuncOneBack = PyObject_CallObject(pFuncOne, nullptr);

    int Index_i = 0, Index_k = 0, Index_m = 0, Index_n = 0;
    if(PyList_Check(FuncOneBack)){

        int SizeOfList = PyList_Size(FuncOneBack);

        for(Index_i = 0; Index_i < SizeOfList; Index_i++){

            PyArrayObject *ListItem = (PyArrayObject *)PyList_GetItem(FuncOneBack, Index_i);

            int Rows = ListItem->dimensions[0], columns = ListItem->dimensions[1];
            cout<<"The "<<Index_i<<"th Array is:"<<endl;
            for(Index_m = 0; Index_m < Rows; Index_m++){

                for(Index_n = 0; Index_n < columns; Index_n++){

                    cout<<*(double *)(ListItem->data + Index_m * ListItem->strides[0] + Index_n * ListItem->strides[1])<<" ";
                }
                cout<<endl;
            }

            Py_DECREF(ListItem);
        }
    }else{

        cout<<"Not a List"<<endl;
    }

    /*Return Integer List and Access to Each Items*/

    cout<<"Integer List Show:"<<endl;
    PyObject *pFuncTwo     = PyDict_GetItemString(pDict, "IntegerListReturn");
    PyObject *FuncTwoBack  = PyObject_CallObject (pFuncTwo, nullptr);

    if(PyList_Check(FuncTwoBack)){

        int SizeOfList = PyList_Size(FuncTwoBack);
        for(Index_i = 0; Index_i < SizeOfList; Index_i++){

            PyObject *ListItem = PyList_GetItem(FuncTwoBack, Index_i);

            int NumOfItems = PyList_Size(ListItem);

            for(Index_k = 0; Index_k < NumOfItems; Index_k++){

                PyObject *Item = PyList_GetItem(ListItem, Index_k);

                cout << PyInt_AsLong(Item) <<" ";

                Py_DECREF(Item);
            }

            Py_DECREF(ListItem);
        }
        cout<<endl;


    }else{

        cout<<"Not a List"<<endl;
    }

    /*Return Float List and Access to Each Items*/

    cout<<"Double List Show:"<<endl;
    PyObject *pFunThree     = PyDict_GetItemString(pDict, "FloatListReturn");
    PyObject *FuncThreeBack = PyObject_CallObject  (pFunThree, nullptr);

    if(PyList_Check(FuncThreeBack)){

        int SizeOfList = PyList_Size(FuncThreeBack);
        for(Index_i = 0; Index_i < SizeOfList; Index_i ++){

            PyObject *ListItem = PyList_GetItem(FuncThreeBack, Index_i);
            int NumOfItems = PyList_Size(ListItem);

            for(Index_k = 0; Index_k < NumOfItems; Index_k++){

                PyObject *Item  = PyList_GetItem(ListItem, Index_k);

                cout<< PyFloat_AsDouble(Item) << " ";

                Py_DECREF(Item);
            }

            Py_DECREF(ListItem);
        }
        cout<<endl;


    }else{

        cout<<"Not a List"<<endl;
    }

    /*Pass by List: Transform an C Array to Python List*/

    double CArray[] = {1.2, 4.5, 6.7, 8.9, 1.5, 0.5};

    PyObject *PyList  = PyList_New(6);
    PyObject *ArgList = PyTuple_New(1);
    for(Index_i = 0; Index_i < PyList_Size(PyList); Index_i++){

        PyList_SetItem(PyList, Index_i, PyFloat_FromDouble(CArray[Index_i]));
    }

    PyObject *pFuncFour = PyDict_GetItemString(pDict, "PassListFromCToPython");
    cout<<"C Array Pass Into The Python List:"<<endl;
    PyTuple_SetItem(ArgList, 0, PyList);
    PyObject_CallObject(pFuncFour, ArgList);

    /*Pass by Python Array: Transform an C Array to Python Array*/

    double CArrays[3][3] = {{1.3, 2.4, 5.6}, {4.5, 7.8, 8.9}, {1.7, 0.4, 0.8}};

    npy_intp Dims[2] = {3, 3};

    PyObject *PyArray  = PyArray_SimpleNewFromData(2, Dims, NPY_DOUBLE, CArrays);
    PyObject *ArgArray = PyTuple_New(1);
    PyTuple_SetItem(ArgArray, 0, PyArray);

    PyObject *pFuncFive = PyDict_GetItemString(pDict, "PassArrayFromCToPython");
    PyObject_CallObject(pFuncFive, ArgArray);



    //Release

    Py_DECREF(pModule);
    Py_DECREF(pDict);
    Py_DECREF(FuncOneBack);
    Py_DECREF(FuncTwoBack);
    Py_DECREF(FuncThreeBack);
    Py_DECREF(PyList);
    Py_DECREF(ArgList);
    Py_DECREF(PyArray);
    Py_DECREF(ArgArray);
    return 0;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167

执行结果: 

这是执行C / C++文件后得到的结果

上面是嵌入式编程的基础,C++中调用python时,传递大型数组是一个大问题,这里使用 boost.python (linux)

  • 下载C++的boost库:boost.org/
  • 解压boost文件,在其目录中执行./bootstrap.sh --with-libraries=all --with-toolset=gcc,会生成编译器b2bjam
  • 修改project-config.jam文件,加入python的版本及路径(不加入则会默认python2.7):

    说明: 如果使用Anaconda 虚拟环境 ,最好修改 .bashrc 文件内容,例如:


这里就会去我的虚拟环境 tensorflow-keras 下去找到 python,不然默认会找到python2.7

编译boost

执行以下命令开始进行boost的编译:

./b2 toolset=gcc
安装boost

最后执行以下命令开始安装boost:

./b2 install --prefix=/usr

--prefix=/usr用来指定boost的安装目录,不加此参数的话默认的头文件在/usr/local/include/boost目录下,库文件在/usr/local/lib/目录下。这里把安装目录指定为--prefix=/usr则boost会直接安装到系统头文件目录和库文件目录下,可以省略配置环境变量

C++代码:

#include<boost/python.hpp>
#include<boost/python/numpy.hpp>
#include<iostream>

namespace p = boost::python;
namespace np = boost::python::numpy;

int main(int argc, char *argv[]){
    \\初始化python解释器
    Py_Initialize();
    \\导入python模块
    p::object pModule = p::import("mine");
    \\导入python函数
    p::object func1 = pModule.attr("func1");

    \\初始化numpy
    np::initialize();
    \\生成ndarray类实例
    uint8_t data_in_c[] = {1,2,3,4,5,6,7,8,1,3,5,7};
    p::tuple shape = p::make_tuple(3, 4);
    p::tuple stride = p::make_tuple(4, 1);
    np::dtype dt1 = np::dtype::get_builtin<uint8_t>();
    np::ndarray data_from_c = np::from_data(data_in_c, dt1,
        shape, stride, p::object());

    \\在C++中输出ndarray
    std::cout << "C++ ndarray:" << std::endl;
    std::cout << p::extract<char const *>(p::str(data_from_c)) << std::endl;
    std::cout << std::endl;

    \\调用python的函数,并传入ndarray,之后取回结果
    p::object data_obj_from_python = func1(data_from_c);;
    \\返回值是p::object类型,转换为np::array类型
    np::ndarray data = np::array(data_obj_from_python);
    \\取出ndarry的数据指针
    \\由于某种原因,data.get_data()得到的数据指针是char *类型,需要转换为对应的数据类型
    \\详见:https://github.com/boostorg/python/blob/develop/include/boost/python/numpy/ndarray.hpp#L41-L55
    double *pp = reinterpret_cast<double*> (data.get_data());

    \\调用python的函数,并传入ndarray
    std::cout << "data from python:" << std::endl;
    std::cout << p::extract<char const *>(p::str(data)) << std::endl;
    std::cout << std::endl;

    std::cout << "pointer:" << std::endl;
    for (int i = 0; i < 9; i++) {
    	std::cout << *(pp+i)  << std::endl;
    }
}

Python代码mine.py(需要跟编译后的exe文件放在同一个目录下):

import numpy as np
data = np.random.random((3,3))

def func1(data_from_C):
    print("data_from_C++.shape:")
    print(data_from_C.shape)
    print('')
    print("data_from_C++:")
    print(data_from_C)
    print('')

    print("data.type:")
    print(data.dtype)
    print('')
    print("data in python")
    print(data)
    print('')

    return data

输出结果:

C++ ndarray:
[[1 2 3 4]
 [5 6 7 8]
 [1 3 5 7]]

data_from_C++.shape:
(3, 4)

data_from_C++:
[[1 2 3 4]
 [5 6 7 8]
 [1 3 5 7]]

data.type:
float64

data in python
[[ 0.70759695  0.39755579  0.9951812 ]
 [ 0.97369017  0.57502282  0.25125566]
 [ 0.92008613  0.74213496  0.64438868]]

data from python:
[[ 0.70759695  0.39755579  0.9951812 ]
 [ 0.97369017  0.57502282  0.25125566]
 [ 0.92008613  0.74213496  0.64438868]]

pointer:
0.707597
0.397556
0.995181
0.97369
0.575023
0.251256
0.920086
0.742135
0.644389

该方法为指针传值,python中的ndarray与C++中的数组共享数据空间。调用及返回的开销极低,完全可以忽略不计,而且使用方法比目前网上所有的方法都要简单。

注意:运行时如果出现错误:

Fatal Python error: Py_Initialize: unable to load the file system codec. 
ImportError: No module named 'encodings'

则需要把 stage\lib 加入环境系统环境变量 PATH,


问题:编译boost 没有boost-python 动态库和静态库

这里在编译boost 时,要保证系统安装python-dev, 这相当于python的扩展库!!!


参考网站:

  1. List Object 对象介绍:https://docs.python.org/2.7/c-api/list.html?highlight=pylist_new#c.PyList_New
  2. Tuple Object 对象介绍:https://docs.python.org/2.7/c-api/tuple.html?highlight=pytuple_new
  3. PyArrayObject对象介绍:https://docs.scipy.org/doc/numpy-1.10.0/reference/c-api.array.html#c.import_array
  4. PyArrayObject对象使用介绍:http://folk.uio.no/hpl/scripting/doc/python/NumPy/Numeric/numpy-13.html
  5. Python与C /C++嵌入式编程:https://www.codeproject.com/Articles/11805/Embedding-Python-in-C-C-Part-I
  6. boost 编译安装:https://blog.csdn.net/this_capslock/article/details/47170313

猜你喜欢

转载自blog.csdn.net/qq_25867649/article/details/79962329