I was just working on a program i made for fun and i came across a problem that i was unable to find a solution to. The code I wrote looked something like this:
import numpy as np
data= np.genfromtxt('list.txt', unpack=True, dtype=("U12", "U12"))
print(data)
'list.txt' looked something like this:
# random random2
foo ßaar
When I try to run this code, the following error-message appears:
UnicodeDecodeError Traceback (most recent call last) C:\Users\syhon\Documents\Test\test.py in () 1 import numpy as np 2 ----> 3 data= np.genfromtxt('list.txt', unpack=True, dtype=("U12", "U12")) 4 print(data)
C:\Users\syhon\Anaconda3\lib\site-packages\numpy\lib\npyio.py in >genfromtxt(fname, dtype, comments, delimiter, skip_header, skip_footer, >converters, missing_values, filling_values, usecols, names, excludelist, >deletechars, replace_space, autostrip, case_sensitive, defaultfmt, unpack, >usemask, loose, invalid_raise, max_rows) 1927 dtype = np.dtype(ttype) 1928 # -> 1929 output = np.array(data, dtype) 1930 if usemask: 1931 if dtype.names:
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 0: ordinal not in range(128)
However, as soon as I remove the ß, the code works just fine. Is there a way to keep the umlauts?