NumPy chararray and whitespace

Discussion in 'Python' started by OKB (not okblacke), Jun 18, 2008.

  1. 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.

    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?

    Thanks,
    --
    --OKB (not okblacke)
    Brendan Barnwell
    "Do not follow where the path may lead. Go, instead, where there is
    no path, and leave a trail."
    --author unknown
     
    OKB (not okblacke), Jun 18, 2008
    #1
    1. Advertising

  2. OKB (not okblacke)

    Robert Kern Guest

    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
     
    Robert Kern, Jun 18, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Oli Filth
    Replies:
    9
    Views:
    3,368
    Uncle Pirate
    Jan 17, 2005
  2. drife
    Replies:
    1
    Views:
    395
    Travis E. Oliphant
    Mar 1, 2006
  3. Replies:
    10
    Views:
    803
    Eric Brunel
    Dec 16, 2008
  4. hierholzer

    convert CharArray to ByteArray

    hierholzer, Jun 13, 2009, in forum: Java
    Replies:
    24
    Views:
    1,786
    Mayeul
    Jun 16, 2009
  5. MRAB
    Replies:
    3
    Views:
    409
Loading...

Share This Page