[Numpy-discussion] Initializing array from buffer

Robert McGibbon rmcgibbo at gmail.com
Mon Nov 17 22:21:32 EST 2014

The np.ndarray constructor
<http://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html> takes
a strides argument argument, and a buffer. Is it not sufficiently flexible?


On Sun, Nov 16, 2014 at 4:27 PM, Sturla Molden <sturla.molden at gmail.com>

> Andrea Arteaga <andyspiros at gmail.com> wrote:
> > My use case is the following: we have a some 3D arrays in our C++
> > framework. The ordering of the elements in these arrays is neither C nor
> > Fortran style: it might be IJK (i.e. C style, 3rd dimension contiguous in
> > memory), KJI (i.e. Fortran style, first dimension contiguous) or, e.g.
> IKJ.
> > Moreover we put some padding to optimize aligned access. This kind of
> > memory structure cannot be just expressed as 'C' or 'Fortran', but it can
> > be perfectly expressed using the Python buffer protocol by providing the
> > shape and the strides. We would like to export this structure to a numpy
> > array that should be able of accessing the same memory locations in a
> > consistent way and make some operations like initializing the content or
> > plotting it.
> >
> > Is this currently possible?
> > If not, is it planned to implement such a feature?
> If you are already coding in C++, just use PyArray_New or
> PyArray_NewFromDescr:
> http://docs.scipy.org/doc/numpy/reference/c-api.array.html#c.PyArray_New
> http://docs.scipy.org/doc/numpy/reference/c-api.array.html#c.PyArray_NewFromDescr
> Apart from that, numpy.array and numpy.asarray can also accept a PEP 3118
> buffer.
> Sturla
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20141117/6399a239/attachment.html>

More information about the NumPy-Discussion mailing list