[SciPy-dev] Example of power of new data-type descriptors.

Francesc Altet faltet at carabos.com
Fri Dec 30 12:46:04 CST 2005

A Dilluns 26 Desembre 2005 10:00, Travis Oliphant va escriure:
> I'd like more people to know about the new power that is in scipy core
> due to the general data-type descriptors that can now be used to define
> numeric arrays.  Towards that effort here is a simple example (be sure
> to use latest SVN -- there were a coupld of minor changes that improve
> usability made recently).  Notice this example does not use a special
> "record" array subclass.  This is just a regular array.

IMO, this is very good stuff and it opens the door to support
homogeneous, heterogeneous and character strings in just one object.
That makes the inclusion of such an object in Python a very big
improvement because people will finally have a very effective
container for virtually *any* kind of large datasets in an easy way.
I'm personally very excited about this new functionality :-)

Just a few kirks (using scipy_core

>  >>> print a[0]
> ('Bill', 31, 260.0)

For me, this prints:

In [87]: a[0]
31, 260.0)

which looks a bit ugly. However:

In [86]: a['name']
Out[86]: array([Bill, Fred], dtype=(string,30))

seems fine.

Also, I find the name of the .getfield() method a bit confusing:

In [71]: a.getfield?
Type:           builtin_function_or_method
Base Class:     <type 'builtin_function_or_method'>
String Form:    <built-in method getfield of scipy.ndarray object at 
Namespace:      Interactive
    m.getfield(dtype, offset) returns a field of the given array as a
    certain type.  A field is a view of the array's data with each
    itemsize determined by the given type and the offset into the
    current array.

So, whoever that generates a heterogeneous generic array may be
tempted to call getfield() in order to get an actual field of the
array and get disapointed. I suggest to change this name by .viewas()
or just .as() and keep the 'getfield' name for heterogeneous datasets.


>0,0<   Francesc Altet     http://www.carabos.com/
V   V   Cárabos Coop. V.   Enjoy Data

More information about the Scipy-dev mailing list