-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[QUESTION] how to access raw data created in C++? #2533
Comments
There's |
thankyou Yannick for the response. My problem is that using py::array the data are copied from c++ to the py::array object. py::scoped_interpreter guard{}; // start the interpreter and keep it alive
py::object main = py::module::import("__main__");
py::object globals = main.attr("__dict__");
double* myVect = new double[100];
memset(myVect, 0, sizeof(double) * 100);
myVect[0] = 1.0;
myVect[99] = 2.0;
size_t size = 100;
py::array pyVect((size_t)100, myVect);
globals["myArray"] = pyVect;
std::cout << myVect[0] << " --- " << myVect[99] << std::endl;
py::exec("print(myArray)");
py::exec("myArray = myArray[::-1]");
py::exec("print(myArray)");
std::cout << myVect[0] << " --- " << myVect[99] << std::endl;
delete[] myVect; the array named EDIT (@YannickJadoul): Surround with ``` |
@IvanM76, have a look at #1042, for example. You need to provide a In your example, where your |
The question seems to have been answered. Closing. |
How is It possibile to create raw data (Dynamic allocated Array) in C++ and passing It as a variable to interpreter in order to modify it Python side but in a way that all the modifications are reflected also in c++ side? I mean something like boost::numpy::ndarray
The text was updated successfully, but these errors were encountered: