Hi,

I'm trying to build-up numpy arrays coming from buffers, and I'm getting a 
somewhat unexpected result.

First, for numeric values, everything seems ok (i.e. the NULL character is 
correctly interpretated), and works equally for both numarray and numpy:

In [98]: numarray.array("a\x00b"*4, dtype='Float32',shape=3)
Out[98]: array([  2.60561966e+20,   8.94319890e-39,   5.92050103e+20], 
type=Float32)

In [99]: numpy.ndarray(buffer="a\x00b"*4, dtype='Float32',shape=3)
Out[99]: array([  2.60561966e+20,   8.94319890e-39,   5.92050103e+20], 
dtype=float32)

However, for string values, numpy seems to work in a strange way. 
The numarray have an expected behaviour, IMO:

In [100]: numarray.strings.array(buffer="a\x00b"*4, itemsize=4, shape=3)
Out[100]: CharArray(['a', '', 'ba'])  

but numpy  haven't:

In [101]: numpy.ndarray(buffer="a\x00b"*4, dtype="S4", shape=3)
Out[101]:
array([aba, ba, bab],
      dtype='|S4')

i.e. it seems like numpy is striping-off NULL chars before building the object 
and I don't think this is correct.

Cheers,

-- 
>0,0<   Francesc Altet     http://www.carabos.com/
V   V   Cárabos Coop. V.   Enjoy Data
 "-"

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Numpy-discussion mailing list
Numpy-discussion@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/numpy-discussion

Reply via email to