Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r73543 - sandbox/numpy/libs/numpy/doc
From: ankitdaf_at_[hidden]
Date: 2011-08-05 05:06:21


Author: ankitdaf
Date: 2011-08-05 05:06:19 EDT (Fri, 05 Aug 2011)
New Revision: 73543
URL: http://svn.boost.org/trac/boost/changeset/73543

Log:
Added tutorial for dtype
Added:
   sandbox/numpy/libs/numpy/doc/dtype.rst (contents, props changed)
Text files modified:
   sandbox/numpy/libs/numpy/doc/Jamfile | 2 +-
   1 files changed, 1 insertions(+), 1 deletions(-)

Modified: sandbox/numpy/libs/numpy/doc/Jamfile
==============================================================================
--- sandbox/numpy/libs/numpy/doc/Jamfile (original)
+++ sandbox/numpy/libs/numpy/doc/Jamfile 2011-08-05 05:06:19 EDT (Fri, 05 Aug 2011)
@@ -6,7 +6,7 @@
 import docutils ;
 
 import path ;
-sources = tutorial.rst ndarray.rst ;
+sources = tutorial.rst dtype.rst ndarray.rst ;
 bases = $(sources:S=) ;
   
 # This is a path relative to the html/ subdirectory where the

Added: sandbox/numpy/libs/numpy/doc/dtype.rst
==============================================================================
--- (empty file)
+++ sandbox/numpy/libs/numpy/doc/dtype.rst 2011-08-05 05:06:19 EDT (Fri, 05 Aug 2011)
@@ -0,0 +1,34 @@
+How to use dtypes
+=================
+
+Here is a brief tutorial to show how to create ndarrays with built-in python data types, and extract the types and values of member variables
+
+Like before, first get the necessary headers, setup the namespaces and initialize the Python runtime and numpy module::
+
+ #include <boost/numpy.hpp>
+ #include <iostream>
+
+ namespace p = boost::python;
+ namespace np = boost::numpy;
+
+ int main(int argc, char **argv)
+ {
+ Py_Initialize();
+ np::initialize();
+
+Next, we create the shape and dtype. We use the get_builtin method to get the numpy dtype corresponding to the builtin C++ dtype
+Here, we will create a 3x3 array passing a tuple with (3,3) for the size, and double as the data type ::
+
+ p::tuple shape = p::make_tuple(3, 3);
+ np::dtype dtype = np::dtype::get_builtin<double>();
+ np::ndarray a = np::zeros(shape, dtype);
+
+Finally, we can print the array using the extract method in the python namespace.
+Here, we first convert the variable into a string, and then extract it as a C++ character array from the python string using the <char const \* > template ::
+
+ std::cout << "Original array:\n" << p::extract<char const *>(p::str(a)) << std::endl;
+
+We can also print the dtypes of the data members of the ndarray by using the get_dtype method for the ndarray ::
+
+ std::cout << "Datatype is:\n" << p::extract<char const *>(p::str(a.get_dtype())) << std::endl ;
+ }


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk