Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r73581 - sandbox/numpy/libs/numpy/doc
From: ankitdaf_at_[hidden]
Date: 2011-08-06 17:12:42


Author: ankitdaf
Date: 2011-08-06 17:12:42 EDT (Sat, 06 Aug 2011)
New Revision: 73581
URL: http://svn.boost.org/trac/boost/changeset/73581

Log:
Added working custom dtype exampel
Text files modified:
   sandbox/numpy/libs/numpy/doc/dtype.rst | 21 +++++++++++++++++++++
   1 files changed, 21 insertions(+), 0 deletions(-)

Modified: sandbox/numpy/libs/numpy/doc/dtype.rst
==============================================================================
--- sandbox/numpy/libs/numpy/doc/dtype.rst (original)
+++ sandbox/numpy/libs/numpy/doc/dtype.rst 2011-08-06 17:12:42 EDT (Sat, 06 Aug 2011)
@@ -31,4 +31,25 @@
 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 ;
+
+We can also create custom dtypes and build ndarrays with the custom dtypes
+
+We use the dtype constructor to create a custom dtype. This constructor takes a list as an argument.
+
+The list should contain one or more tuples of the format (variable name, variable type)
+
+So first create a tuple with a variable name and its dtype, double, to create a custom dtype ::
+
+ p::tuple for_custom_dtype = p::make_tuple("ha",dtype) ;
+
+Next, create a list, and add this tuple to the list. Then use the list to create the custom dtype ::
+
+ p::list list_for_dtype ;
+ list_for_dtype.append(for_custom_dtype) ;
+ np::dtype custom_dtype = np::dtype(list_for_dtype) ;
+
+We are now ready to create an ndarray with dimensions specified by \*shape\* and of custom dtpye ::
+
+ np::ndarray new_array = np::zeros(shape,custom_dtype);
+
         }


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