[C++-sig] Re: Creating an array in C++

Philip Austin paustin at eos.ubc.ca
Thu Feb 26 04:41:48 CET 2004


David Abrahams writes:
 > Does this work?
 > 
 >      handle<> m = ::PyImport_Import(str("numarray").ptr())
 >      object numarray(m);
 >      numeric::array theArray(make_tuple(300),numarray.attr("UInt8"));

Unfortunately, without the keyword it interprets the shape array as data:

>>> theArray=numarray.array((300,),numarray.UInt8)
>>> theArray
array([44], type=UInt8)

 > 
 > You have to take theArray.ptr() to get the python object back if you
 > want access to its raw memory.

Yes, that adds a dependency on PyArrayObject, but there's really no
alternative to memcpy if you're moving big arrays back and fort.

Phil





More information about the Cplusplus-sig mailing list