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

David Abrahams dave at boost-consulting.com
Thu Feb 26 01:13:52 CET 2004

Philip Austin <paustin at eos.ubc.ca> writes:

> David Abrahams writes:
>  > 
>  > Excuse me?  Alpha?!
>  > 
>  > It may be missing a couple of features, but it's hardly alpha
>  > software.
> Sorry, that was a careless choice of words.  We use numeric::array
> daily without a hitch, but like Marc-Alexis I'm not sure how to create
> an empty array of arbitray shape and type using the boost python
> array constructor.
>> What python argument value do you expect to be passed to the python
>> object's __init__ function?
> Our most common requirement is to be able to do something like
> theArray=numarray.array(shape=(300,),type=numarray.UInt8)
> from the C++ side

Does this work?

     handle<> m = ::PyImport_Import(str("numarray").ptr())
     object numarray(m);
     numeric::array theArray(make_tuple(300), numarray.attr("UInt8"));

Yeah, it's ugly.

> and then fill it with values returned from C or Fortran.

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

Dave Abrahams
Boost Consulting

More information about the Cplusplus-sig mailing list