Change values in argument array in pybind11

Viewed 166

I have the following small pybind11 code:

void f(
    Eigen::MatrixXd& vertices
){
    vertices(0, 0) = 55.0;
}

PYBIND11_MODULE(test, m) {
    m.def("f", &f, "");
}

And the corresponding Python:

v = np.array([[1, 2], [1, 2]])
f(v)
print(v)

So basically, I create a Numpy array, and the Python bindings are supposed to write 55 into one of the array cells.

Unfortunately, when printing v, it seems that 55 was not written into it.

How can I achieve that the changes to the array in the C++ code also take effect in the Python code?

0 Answers
Related