Go to the documentation of this file.00001
00002
00003
00004
00005
00011 #include <boost/numpy.hpp>
00012 #include <iostream>
00013
00014 namespace p = boost::python;
00015 namespace np = boost::numpy;
00016
00017
00018 int main(int argc, char **argv)
00019 {
00020
00021 Py_Initialize();
00022
00023 np::initialize();
00024
00025 int arr[] = {1,2,3,4} ;
00026
00027 np::ndarray py_array = np::from_data(arr, np::dtype::get_builtin<int>() , p::make_tuple(4), p::make_tuple(4), p::object());
00028
00029 std::cout << "C++ array :" << std::endl ;
00030 for (int j=0;j<4;j++)
00031 {
00032 std::cout << arr[j] << ' ' ;
00033 }
00034 std::cout << std::endl << "Python ndarray :" << p::extract<char const *>(p::str(py_array)) << std::endl;
00035
00036 py_array[1] = 5 ;
00037
00038 std::cout << "Is the change reflected in the C++ array used to create the ndarray ? " << std::endl ;
00039 for (int j = 0;j<4 ; j++)
00040 {
00041 std::cout << arr[j] << ' ' ;
00042 }
00043
00044 arr[2] = 8 ;
00045
00046 std::cout << std::endl << "Is the change reflected in the Python ndarray ?" << std::endl << p::extract<char const *>(p::str(py_array)) << std::endl;
00047
00048 }