numpy.genfromtxt with Python3 - howto

  • Thread starter Helmut Jarausch
  • Start date
H

Helmut Jarausch

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)
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top