[Numpy-discussion] Empty strings not empty?
Thu Dec 31 04:13:51 CST 2009
On Thu, Dec 31, 2009 at 2:08 AM, Christopher Barker
> Charles R Harris wrote:
>> That is due to type promotion for the ufunc call:
>> In : a1 = np.array('a\x00\x00\x00')
>> n : np.array(['a'], dtype=a1.dtype)
>> Out: 'a'
>> In : np.array(['a'], dtype=a1.dtype).tostring()
>> Out: 'a\x00\x00\x00'
> it took me a bit to figure out what this meant, so in case I'm not the
> only one, I thought I'd spell it out:
I think the summary here is 'numpy strings are zero padded; therefore
you may run into surprises with a string that has trailing zeros'.
I see why that is - the zero terminator is the only way for numpy
arrays to see where the end of the string is...
More information about the NumPy-Discussion