|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r73532 - sandbox/numpy/libs/numpy/example
From: ankitdaf_at_[hidden]
Date: 2011-08-04 13:39:05
Author: ankitdaf
Date: 2011-08-04 13:39:04 EDT (Thu, 04 Aug 2011)
New Revision: 73532
URL: http://svn.boost.org/trac/boost/changeset/73532
Log:
Added from_data implementation, zeros(..) examples
Text files modified:
sandbox/numpy/libs/numpy/example/ndarray.cpp | 14 +++++++++++++-
sandbox/numpy/libs/numpy/example/simple.cpp | 2 ++
2 files changed, 15 insertions(+), 1 deletions(-)
Modified: sandbox/numpy/libs/numpy/example/ndarray.cpp
==============================================================================
--- sandbox/numpy/libs/numpy/example/ndarray.cpp (original)
+++ sandbox/numpy/libs/numpy/example/ndarray.cpp 2011-08-04 13:39:04 EDT (Thu, 04 Aug 2011)
@@ -3,6 +3,8 @@
* The Python sequence could be any object whose __array__ method returns an array, or any (nested) sequence.
*
* @todo Find a way to create a list explicitly
+ *
+
*
*/
@@ -23,11 +25,21 @@
np::ndarray example_tuple = np::array (tu) ;
// and from a list
p::list l ;
- l.append('a') ;
np::ndarray example_list = np::array (l) ;
// Optionally, you can also specify a dtype
np::dtype dt = np::dtype::get_builtin<int>();
np::ndarray example_list1 = np::array (l,dt);
+ // You can also create an array by supplying data.First,create an integer array
+ int data[] = {1,2,3,4} ;
+ // Create a shape, and strides, needed by the function
+ p::tuple shape = p::make_tuple(2,2) ;
+ p::tuple strides = p::make_tuple(strides(data)) ;
+ // The function also needs an owner, to keep track of the data array passed. Passing none is dangerous
+ p::object owner ;
+ // The from_data function takes the data array, datatype,shape,stride and owner as arguments
+ // and returns an ndarray
+ np::ndarray data_ex1 = np::from_data(data,dt, shape,strides,owner);
+
}
Modified: sandbox/numpy/libs/numpy/example/simple.cpp
==============================================================================
--- sandbox/numpy/libs/numpy/example/simple.cpp (original)
+++ sandbox/numpy/libs/numpy/example/simple.cpp 2011-08-04 13:39:04 EDT (Thu, 04 Aug 2011)
@@ -21,6 +21,8 @@
np::dtype dtype = np::dtype::get_builtin<float>();
// Construct an array with the above shape and type
np::ndarray a = np::zeros(shape, dtype);
+ // Construct an empty array with the above shape and dtype as well
+ np::ndarray b = np::empty(shape,dtype);
// Print the array
std::cout << "Original array:\n" << p::extract<char const *>(p::str(a)) << std::endl;
// Reshape the array into a 1D array
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