[Numpy-discussion] Casting RecArray fields?

dHering vel.accel at gmail.com
Tue Jan 31 02:56:00 CST 2006


On 1/31/06, Francesc Altet <faltet at carabos.com> wrote:
>
> A Dimarts 31 Gener 2006 10:46, dHering va escriure:
> > Hi all,
> >
> > I need to cast fields of type 'Bool' to type 'Int32'.
> > I'm not sure how to do this.
> >
> > Thank you,
> > Dieter
> >
> >
> > import numarray.records as rec
> >
> > b = rec.array([[23, 0],[45, 1]], names=' integer,
> boolean',formats='Int32,
> > Bool')
> >
> > print b.field(1).type()
> > #  following line is not permissable
> > #  b.field(1) = b.field(1).astype('Int32')
> > b.field(1)[:] = b.field(1).astype('Int32')
> > print b.field(1).type()
>
> You can't do this because this implies a change on the column type
> definition (and also in the type size) of the recarray.
>
> One way that works for me, but that implies a complete data copy, is:
>
> In [15]: c = rec.array([b.field(0),b.field(1)], formats='Int32,Int32')
>
> In [16]: c.field(1)
> Out[16]: array([0, 1])
>
> HTH,
>
> --
> >0,0<   Francesc Altet http://www.carabos.com/
> V   V   Cárabos Coop. V. Enjoy Data
> "-"


Yes it helps very much Francesc.
Thank you.
Dieter
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20060131/adfd4e5a/attachment-0001.html 


More information about the Numpy-discussion mailing list