From: Francesc A. <fa...@ca...> - 2006-09-29 15:19:10
|
Hi, I'm trying to build-up numpy arrays coming from buffers, and I'm getting a= =20 somewhat unexpected result. =46irst, for numeric values, everything seems ok (i.e. the NULL character i= s=20 correctly interpretated), and works equally for both numarray and numpy: In [98]: numarray.array("a\x00b"*4, dtype=3D'Float32',shape=3D3) Out[98]: array([ 2.60561966e+20, 8.94319890e-39, 5.92050103e+20],=20 type=3DFloat32) In [99]: numpy.ndarray(buffer=3D"a\x00b"*4, dtype=3D'Float32',shape=3D3) Out[99]: array([ 2.60561966e+20, 8.94319890e-39, 5.92050103e+20],=20 dtype=3Dfloat32) However, for string values, numpy seems to work in a strange way.=20 The numarray have an expected behaviour, IMO: In [100]: numarray.strings.array(buffer=3D"a\x00b"*4, itemsize=3D4, shape= =3D3) Out[100]: CharArray(['a', '', 'ba']) =20 but numpy haven't: In [101]: numpy.ndarray(buffer=3D"a\x00b"*4, dtype=3D"S4", shape=3D3) Out[101]: array([aba, ba, bab], dtype=3D'|S4') i.e. it seems like numpy is striping-off NULL chars before building the obj= ect=20 and I don't think this is correct. Cheers, =2D-=20 >0,0< Francesc Altet =A0 =A0 http://www.carabos.com/ V V C=E1rabos Coop. V. =A0=A0Enjoy Data "-" |