numpy.genfromtxt with Python3 - howto

Discussion in 'Python' started by Helmut Jarausch, Apr 6, 2012.

  1. Hi

    I have a machine with a non-UTF8 local.
    I can't figure out how to make numpy.genfromtxt work

    I pipe some ascii data into the following script but get this
    bytes to str hell.

    Many thanks for a hint,
    Helmut.


    #!/usr/bin/python3
    import numpy as np
    import io
    import sys

    inpstream = io.open(sys.stdin.fileno(), "r", encoding='latin1')

    data = np.genfromtxt(inpstream)
    '''
    Traceback (most recent call last):
    File "SimpleMatInp.py", line 8, in <module>
    data = np.genfromtxt(inpstream)
    File "/usr/lib64/python3.2/site-packages/numpy/lib/npyio.py", line
    1274, in genfromtxt
    first_values = split_line(first_line)
    File "/usr/lib64/python3.2/site-packages/numpy/lib/_iotools.py", line
    206, in _delimited_splitter
    line = line.split(self.comments)[0].strip(asbytes(" \r\n"))
    TypeError: Can't convert 'bytes' object to str implicitly
    '''
    print(data)

    print(data.dtype)

    print(data.shape)
     
    Helmut Jarausch, Apr 6, 2012
    #1
    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. drife
    Replies:
    1
    Views:
    388
    Travis E. Oliphant
    Mar 1, 2006
  2. Duncan Smith
    Replies:
    3
    Views:
    441
    Duncan Smith
    Apr 25, 2007
  3. Replies:
    2
    Views:
    509
    Robert Kern
    Nov 13, 2007
  4. simona bellavista

    genfromtxt and comment identifier

    simona bellavista, Apr 15, 2011, in forum: Python
    Replies:
    1
    Views:
    544
    Peter Otten
    Apr 15, 2011
  5. frankenstein
    Replies:
    0
    Views:
    401
    frankenstein
    Apr 4, 2012
Loading...

Share This Page