[Numpy-discussion] Empty strings not empty?

Matthew Brett matthew.brett at gmail.com
Tue Dec 29 18:52:36 EST 2009


Hi,

> I don't see any empty string in your code ? They all have one byte.
> The last one is slightly confusing as far as printing is concerned (I
> would have expected array(["¥x00"]...) instead). It may be a bug in
> numpy because a byte with value 0 is used a string delimiter in C.

Sorry - I pasted the wrong code:

In [49]: e = np.array([''])

In [50]: e.shape
Out[50]: (1,)

In [51]: e.size
Out[51]: 1

In [52]: f = np.array(['a'])

In [53]: f.shape == e.shape
Out[53]: True

In [54]: f.size == e.size
Out[54]: True

In [55]: e.tostring()
Out[55]: '\x00'

In [56]: f.tostring()
Out[56]: 'a'


In [58]: e == z
Out[58]: array([ True], dtype=bool)

Thanks,

Matthew



More information about the NumPy-Discussion mailing list