For some reason, I decided to save my list of data as a string. If I use
f = open('tarfile.txt')
for line in f.readlines():
print line
f.close()
my output looks like:
[ 53.7775 13.4375 26.525 48.63 125. 185. 653. ]
[ 53.7775 13.33625 26.73375 48.68375 125. 185. 653. ]
[ 53.7775 13.325 27.11375 48.8875 126. 187. 653. ]
[ 53.7775 13.43625 27.3175 48.92875 126. 187. 653. ]
[ 53.7775 14.4825 33.07375 51.7325 141. 202. 595. ]
I would like to read this data in to 2D array. I have searched and tried various methods such as pickle, eval, json, etc but nothing worked
If you are using numpy
(or don't mind using it), you can do numpy.loadtxt('tarfile.txt', usecols=range(1,8))
. It is particularly nice if you are going to want your data in a 2-d numpy
array anyway.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With