[MATRIX-SIG] Extending NumPy

Konrad Hinsen hinsen@ibs.ibs.fr
Wed, 20 Aug 1997 10:51:50 +0200


> If you can deal with a bit of overhead, maybe
> you should use the abstract object interface
> (thanks again Jim Fulton!) to extract Python
> objects from sequences and get their values.

For values passed into a function there is some merit to this
approach, but for large amounts of data it is not very efficient,
and it's certainly more complicated to code.

If you want to accept an arbitrary sequence object and convert it
to an array, just call PyArray_ContiguousFromObject(). That's
more or less what Numeric.array() is at the Python level.
You get a contiguous array that is easy to work on.

For returning data, constructing an array is probably much easier than
creating any other type of sequence object. Just call
PyArray_FromDims(), which creates a contiguous array, and fill it with
your data.

Konrad.
-- 
-------------------------------------------------------------------------------
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
_______________