[Numpy-discussion] Rename record array fields (with object arrays)

Sameer DCosta sameerslists@gmail....
Thu Feb 28 10:35:43 CST 2008


Hi,

I'm having trouble renaming record array fields if they contain object
arrays in them. I followed the solutions posted by Robert Kern and
Stefan van der Walt  (Thanks again) but it doesn't look like this
method works in all cases. For reference:
http://projects.scipy.org/pipermail/numpy-discussion/2008-February/031509.html

In [1]: from numpy import *

In [2]: olddt = dtype([('foo', '|O4'), ('bar', float)])

In [3]: a = zeros(10, olddt)

In [4]: a
Out[4]:
array([(0, 0.0), (0, 0.0), (0, 0.0), (0, 0.0), (0, 0.0), (0, 0.0),
       (0, 0.0), (0, 0.0), (0, 0.0), (0, 0.0)],
      dtype=[('foo', '|O4'), ('bar', '<f8')])

In [5]: newdt = dtype([('notfoo', '|O4'), ('notbar', float)])

In [6]: b = a.view(newdt)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)

/home/titan/sameer/projects/<ipython console>

TypeError: Cannot change data-type for object array.


--
Sameer


More information about the Numpy-discussion mailing list