[Numpy-discussion] chararray stripping trailing whitespace a bug?

Neil Crighton neilcrighton at gmail.com
Mon May 10 11:23:12 EDT 2010


I've been working with pyfits, which uses numpy chararrays. I've discovered the 
hard way that chararrays silently remove trailing whitespace: 

>>> a = np.array(['a '])
>>> b = a.view(np.chararray)
>>> a[0]
'a '
>>> b[0]
'a'

Note the string values stored in memory are unchanged. This behaviour caused a
bug in a program I've been writing, and seems like a bad idea in general. Is it 
intentional?

Neil





More information about the NumPy-Discussion mailing list