[Numpy-discussion] Reversing RecArrays

Todd Miller jmiller at stsci.edu
Wed Mar 9 13:55:09 EST 2005


On Wed, 2005-03-09 at 13:46, Francesc Altet wrote:
> Hi,
> 
> I would be interested in having a fast way to reverse RecArrays.
> Regrettably, the most straightforward way to reverse them does not
> work properly:
> 
> >>> from numarray import records
> >>> r = records.array([('Smith', 1234),\
> ...                ('Johnson', 1001),\
> ...                ('Williams', 1357),\
> ...                ('Miller', 2468)], \
> ...                names='Last_name, phone_number')
> >>> r[::-1]
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
>   File "/usr/lib/python2.3/site-packages/numarray/records.py", line 749, in 
> __repr__
>     outlist.append(Record.__str__(i))
>   File "/usr/lib/python2.3/site-packages/numarray/records.py", line 797, in 
> __str__
>     outlist.append(`self.array.field(i)[self.row]`)
>   File "/usr/lib/python2.3/site-packages/numarray/records.py", line 736, in 
> field
>     self._fields = self._get_fields()  # Refresh the cache
>   File "/usr/lib/python2.3/site-packages/numarray/records.py", line 705, in 
> _get_fields
>     bytestride=_stride)
>   File "/usr/lib/python2.3/site-packages/numarray/strings.py", line 112, in 
> __init__
>     raise ValueError("Inconsistent string and array parameters.")
> ValueError: Inconsistent string and array parameters.
> 
> Anyway, anybody knows if there is some way to achieve this (until this
> bug would be eventually fixed, of course)?

This now works in CVS.  The attached reverse() also works against CVS
and should work against 1.2.2.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: revrec.py
Type: text/x-python
Size: 708 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20050309/3bafa00d/attachment.py>


More information about the NumPy-Discussion mailing list