Go to the documentation of this file.00001
00002
00003
00004
00005
00014 #include <boost/numpy.hpp>
00015 #include <iostream>
00016
00017 namespace p = boost::python;
00018 namespace np = boost::numpy;
00019
00020 #if _MSC_VER
00021 using boost::uint8_t;
00022 #endif
00023
00024 int main(int argc, char **argv)
00025 {
00026
00027 Py_Initialize();
00028
00029 np::initialize();
00030
00031 p::object tu = p::make_tuple('a','b','c') ;
00032 np::ndarray example_tuple = np::array (tu) ;
00033
00034 p::list l ;
00035 np::ndarray example_list = np::array (l) ;
00036
00037 np::dtype dt = np::dtype::get_builtin<int>();
00038 np::ndarray example_list1 = np::array (l,dt);
00039
00040 int data[] = {1,2,3,4} ;
00041
00042 p::tuple shape = p::make_tuple(4) ;
00043 p::tuple stride = p::make_tuple(4) ;
00044
00045 p::object own ;
00046
00047
00048 np::ndarray data_ex = np::from_data(data,dt,shape,stride,own);
00049
00050 std::cout << "Single dimensional array ::" << std::endl << p::extract < char const * > (p::str(data_ex)) << std::endl ;
00051
00052
00053 uint8_t mul_data[][4] = {{1,2,3,4},{5,6,7,8},{1,3,5,7}};
00054
00055
00056 shape = p::make_tuple(3,2) ;
00057
00058 stride = p::make_tuple(4,2) ;
00059
00060 np::dtype dt1 = np::dtype::get_builtin<uint8_t>();
00061
00062 np::ndarray mul_data_ex = np::from_data(mul_data,dt1, p::make_tuple(3,4),p::make_tuple(4,1),p::object());
00063 std::cout << "Original multi dimensional array :: " << std::endl << p::extract < char const * > (p::str(mul_data_ex)) << std::endl ;
00064
00065 mul_data_ex = np::from_data(mul_data,dt1, shape,stride,p::object());
00066
00067 std::cout << "Selective multidimensional array :: "<<std::endl << p::extract < char const * > (p::str(mul_data_ex)) << std::endl ;
00068
00069 }
00070
00071