4 .. contents :: Table of Contents
6 A `dtype`_ is an object describing the type of the elements of an ndarray
8 .. _dtype: http://docs.scipy.org/doc/numpy/reference/arrays.dtypes.html#data-type-objects-dtype
10 ``<boost/python/numpy/dtype.hpp>`` contains the method calls necessary to generate a python object equivalent to a numpy.dtype from builtin C++ objects, as well as to create custom dtypes from user defined types
25 class dtype : public object
27 static python::detail::new_reference convert(object::object_cref arg, bool align);
30 // Convert an arbitrary Python object to a data-type descriptor object.
32 explicit dtype(T arg, bool align=false);
34 // Get the built-in numpy dtype associated with the given scalar template type.
35 template <typename T> static dtype get_builtin();
37 // Return the size of the data type in bytes.
38 int get_itemsize() const;
51 explicit dtype(T arg, bool align=false)
53 :Requirements: ``T`` must be either :
55 * a built-in C++ typename convertible to object
56 * a valid python object or convertible to object
58 :Effects: Constructs an object from the supplied python object / convertible
59 to object / builtin C++ data type
65 template <typename T> static dtype get_builtin();
67 :Requirements: The typename supplied, ``T`` must be a builtin C++ type also supported by numpy
69 :Returns: Numpy dtype corresponding to builtin C++ type
76 int get_itemsize() const;
78 :Returns: the size of the data type in bytes.
86 namespace p = boost::python;
87 namespace np = boost::python::numpy;
89 np::dtype dtype = np::dtype::get_builtin<double>();
90 p::tuple for_custom_dtype = p::make_tuple("ha",dtype);
91 np::dtype custom_dtype = np::dtype(list_for_dtype);