|
From: Francesc A. <fa...@ca...> - 2006-01-31 10:45:09
|
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 =3D rec.array([[23, 0],[45, 1]], names=3D' integer, boolean',formats=3D=
'Int32,
> Bool')
>
> print b.field(1).type()
> # following line is not permissable
> # b.field(1) =3D b.field(1).astype('Int32')
> b.field(1)[:] =3D 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 =3D rec.array([b.field(0),b.field(1)], formats=3D'Int32,Int32')
In [16]: c.field(1)
Out[16]: array([0, 1])
HTH,
=2D-=20
>0,0< Francesc Altet =A0 =A0 http://www.carabos.com/
V V C=E1rabos Coop. V. =A0=A0Enjoy Data
"-"
|