Python: Restore array to a single line during import from .txt file
A program writes lists to a .txt file in the following manner:
[ 3. 6. 3. 1. 1. 1. 0. 1. 2. 2. 9. 2. 5. 2. 2. 1. 0. 0.
4. 6. 1. 1. 1. 0. 5. 2. 0. 0. 0. 0. 0. 0. 0. 0.]
[ 4. 9. 8. 7. 2. 4. 1. 7. 5. 3. 7. 2. 6. 0. 9.
5. 6. 10. 6. 2. 1. 5. 0.]
[ 3. 5. 9. 1. 1. 1. 0. 1. 1. 4. 8. 5. 5. 3. 3.
7. 6. 12. 9. 2. 1. 0. 0. 4. 6. 1. 1. 1. 0. 5.
0. 0. 0. 0. 0. 0. 0. 0. 0.]
I.e., the lists are not on one line. I want to create a histogram for each
of these lists, how do I import these are integer values in a list after
making sure the whole list (and not one single line) is imported? I have
tried:
data = [line.strip() for line in open('n.txt', 'r')]
But when calling data[0] it just yields the top line. Any suggestions?
No comments:
Post a Comment