pybind11:numpy 2D转c++的Eigen

参考网址
CMakeLists.txt文件

cmake_minimum_required(VERSION 2.8.12)
project(shp)

# Eigen
include_directories("/usr/include/eigen3")

add_subdirectory(pybind11)
pybind11_add_module(shp shape_detection.cpp)

cpp文件

#include 
#include 
Eigen::MatrixXd transpose(const Eigen::MatrixXd &xs)
{
  return xs.transpose();
}

PYBIND11_MODULE(shp, m)
{
    // optional module docstring
    m.doc() = "pybind11 example plugin";
    m.def("transpose", &transpose, "transpose");
}

python文件

import shapes.build.shp as shp # 根据自己的so文件位置写
import numpy as np
a=np.array([[1,2,3],[4,5,6]])
rst=shp.transpose(a)
print(rst)

你可能感兴趣的:(编程技术)