2
0
mirror of https://github.com/boostorg/python.git synced 2026-01-21 05:02:17 +00:00

Added from_data implementation, zeros(..) examples

This commit is contained in:
Ankit Daftery
2011-08-04 17:39:04 +00:00
parent 37a73f344b
commit 45e52301e9
2 changed files with 15 additions and 1 deletions

View File

@@ -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 @@ int main(int argc, char **argv)
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);
}