simple.cpp
Go to the documentation of this file.
00001 // Copyright 2011 Stefan Seefeld.
00002 // Distributed under the Boost Software License, Version 1.0. (See
00003 // accompanying file LICENSE_1_0.txt or copy at
00004 // http://www.boost.org/LICENSE_1_0.txt)
00005 
00006 #include <boost/numpy.hpp>
00007 #include <iostream>
00008 
00009 namespace p = boost::python;
00010 namespace np = boost::numpy;
00011 
00012 int main(int argc, char **argv)
00013 {
00014   // Initialize the Python runtime.
00015   Py_Initialize();
00016   // Initialize NumPy
00017   np::initialize();
00018   // Create a 3x3 shape...
00019   p::tuple shape = p::make_tuple(3, 3);
00020   // ...as well as a type for C++ float
00021   np::dtype dtype = np::dtype::get_builtin<float>();
00022   // Construct an array with the above shape and type
00023   np::ndarray a = np::zeros(shape, dtype);
00024   // Construct an empty array with the above shape and dtype as well
00025   np::ndarray b = np::empty(shape,dtype);
00026   // Print the array
00027   std::cout << "Original array:\n" << p::extract<char const *>(p::str(a)) << std::endl;
00028   // Reshape the array into a 1D array
00029   a = a.reshape(p::make_tuple(9));
00030   // Print it again.
00031   std::cout << "Reshaped array:\n" << p::extract<char const *>(p::str(a)) << std::endl;
00032 }


boost_numpy
Author(s): Jim Bosch, Ankit Daftery
autogenerated on Fri Aug 28 2015 10:10:40