[PYTHON MATRIX-SIG] NumPy and PIL extension module
Jean-Bernard ADDOR
jbaddor@phy.ulaval.ca
Mon, 5 May 1997 19:39:32 -0400 (EDT)
If I understand right, array are not accessed throught iterators ?
A bientot,
Jean-Bernard
On Mon, 5 May 1997, Konrad Hinsen wrote:
> > Most of what I need the data for will probably require floating point
> > values -- this isn't really the big issue for me though. Could someone
> > post how to access and change an array element in an efficient manner in C
> > (ie. not a lot of Python overhead)? The code in multiarraymodule isn't
> > well commented so I don't really understand what is going on.
>
> If you have to access an arbitrary array, things become a bit
> complicated. It is much easier to deal with contiguous arrays.
> A newly created array is always contiguous, for example, as are
> arrays that are the result of any computation. Only indexing and
> other structural operations create non-contiguous arrays.
>
> You can ensure that you are dealing with a contiguous array by calling
> PyArray_ContiguousFromObject(). This function will return a contiguous
> array unchanged, and return a contiguous copy for a non-contiguous
> array. Only if you can't affort the overhead of a potential copy
> you should try to deal with arbitrary arrays - in which case I
> can only wish you good luck ;-)
>
> Now for accessing contiguous arrays. If "array" is a variable
> of type PyArrayObject, then array->data points to its data space.
> You will have to cast this to the correct pointer type according
> to the type of the elements. The data is organized just like in
> a statically allocated C array, i.e. the last index varies fastest.
>
> So all you need is the information about the shape to be able to
> access anything you want. And that's easy: the number of dimensions is
> array->nd, and the list of dimensions is pointed to by
> array->dimensions.
>
> I expect that eventually we'll want better C API support for
> accessing arrays, but I suppose it won't happen soon...
> --
> -------------------------------------------------------------------------------
> Konrad Hinsen | E-Mail: hinsen@ibs.ibs.fr
> Laboratoire de Dynamique Moleculaire | Tel.: +33-4.76.88.99.28
> Institut de Biologie Structurale | Fax: +33-4.76.88.54.94
> 41, av. des Martyrs | Deutsch/Esperanto/English/
> 38027 Grenoble Cedex 1, France | Nederlands/Francais
> -------------------------------------------------------------------------------
>
> _______________
> MATRIX-SIG - SIG on Matrix Math for Python
>
> send messages to: matrix-sig@python.org
> administrivia to: matrix-sig-request@python.org
> _______________
>
_______________
MATRIX-SIG - SIG on Matrix Math for Python
send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org
_______________