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

Hugo Gamboa hgamboa at gmail.com
Sat Jan 7 17:11:43 CST 2006


I was looking at these new datatype mechanisms, and was unable to make
an array string compare.

example: (using Travis code)

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

In [50]: a['name']=='Bill'
Out[50]: False

In [51]: a['name'].__eq__('Bill')
Out[51]: NotImplemented


I expected that a['name']=='Bill' would return [True, False]

Am I trying something in a wrong way?

Is this related to chararray and I should use methods from that class?

Hugo Gamboa


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
>
>
>
>
>
>
>
> _______________________________________________
> Scipy-dev mailing list
> Scipy-dev at scipy.net
> http://www.scipy.net/mailman/listinfo/scipy-dev
>




More information about the Scipy-dev mailing list