Skip to content

Instantly share code, notes, and snippets.

@vlzx
vlzx / call_python.cpp
Last active January 19, 2024 09:28
Call Python code from C++
#include <iostream>
#include <pybind11/embed.h> // everything needed for embedding
#include <pybind11/numpy.h>
namespace py = pybind11;
py::array_t<double> create2DArray(int rows, int cols) {
py::array_t<double> result({rows, cols});
auto ptr = result.mutable_data();
/*
ptr[0] | ptr[1] | ptr[2]