NumPy chararray and whitespace

Robert Kern robert.kern at gmail.com
Wed Jun 18 17:16:08 EDT 2008


OKB (not okblacke) wrote:
>     	Hi.  I'm trying to use NumPy's chararray class for an array of 
> characters.  I notice that when I try to set a chararray element to a 
> space, it actually gets set to an empty string.  I found some pages 
> online indicating that the chararray strips trailing whitespace from its 
> values.

You should ask numpy questions on the numpy mailing list.

   http://www.scipy.org/Mailing_Lists

>     	I am really, really, hoping this is not a hard-coded, unalterable 
> behavior.  Is there a way to get NumPy chararray to include the 
> characters I tell it to, without modificiation?

Sure. Just subclass chararray and redefine __getitem__ to do what you want.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
  that is made terrible by our own mad attempt to interpret it as though it had
  an underlying truth."
   -- Umberto Eco




More information about the Python-list mailing list