I tried to create an array from a text file.
I saw earlier that numpy had a method loadtxt
, so I try it, but it add some junk character before each row...
# my txt file
.--``--.
.--` `--.
| |
| |
`--. .--`
`--..--`
# my python v3.4 program
import numpy as np
f = open('tile', 'r')
a = np.loadtxt(f, dtype=str, delimiter='\n')
print(a)
# my print output
["b' .--``--. '"
"b'.--` `--.'"
"b'| |'"
"b'| |'"
"b'`--. .--`'"
"b' `--..--` '"]
What are these 'b' and double quotes ? And where do they come from ? I tried some solution picked from internet, like open the file with codecs, change the dtype by 'S20', 'S11', and a lot of other things which don't work... What I expect is an array of unicode strings which look like this :
[[' .--``--. ']
['.--` `--.']
['| |']
['| |']
['`--. .--`']
[' `--..--` ']]
Info: I'm using python 3.4 and numpy from the debian stable repository