[Numpy-discussion] Example of power of new data-type descriptors.

dHering vel.accel at gmail.com
Wed Dec 28 16:39:08 CST 2005


On 12/26/05, Travis Oliphant <oliphant.travis at ieee.org> wrote:
>
>
> 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.  I'm kind of
> intrigued (though not motivated to pursue) the possibility of accessing
> (or defining) databases directly into scipy_core arrays using the record
> functionality.
>
> # Define a new data-type descriptor
>  >>> import scipy
>
>  >>> dtype = scipy.dtypedescr({'names': ['name', 'age', 'weight'],
> 'formats': ['S30', 'i2', 'f4']})
>  >>> a = scipy.array([('Bill',31,260),('Fred',15,135)], dtype=dtype)
> # the argument to dtypedescr could have also been placed here as the
> argument to dtype
>
>  >>> print a['name']
> [Bill Fred]
>
>  >>> print a['age']
> [31 15]
>
>  >>> print a['weight']
> [ 260.  135.]
>
>  >>> print a[0]
> ('Bill', 31, 260.0)
>
>  >>> print a[1]
> ('Fred', 15, 135.0)
>
> It seems to me there are some very interesting possibilities with this
> new ability.  The record array subclass adds an improved scalar type
> (the record) and attribute access to get at the fields:  (e.g.  a.name,
> a.age, and a.weight).    But, if you don't need attribute access you can
> use regular arrays to do a lot of what you might need a record array to
> accomplish for you.  I'd love to see what people come up with using this
> new facility.
>
> The new array PEP for Python basically proposes adding a very simple
> array object (just the basic PyArrayObject * of Numeric with a
> bare-bones type-object table) plus this new data-type descriptor object
> to Python and a very few builtin data-type descriptors (perhaps just
> object initially).   This would basically add the array interface to
> Python directly and allow people to start using it generally.  The PEP
> is slow going because it is not on my priority list right now because it
> is not essential to making scipy_core work well.  But, I would love to
> have more people ruminating on the basic ideas which I think are
> crystallizing.
>
> Best wishes for a new year,
>
> -Travis Oliphant
>
>
>
>
>
>
>
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
> for problems?  Stop!  Download the new AJAX search engine that makes
> searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
> http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/numpy-discussion
>




More information about the Numpy-discussion mailing list