0

I wanted to change a text file into a two-dimensional numpy array. my text file looks like this if opened.

01110111110111010111011101110111010111011111010101110101011101110
01000001000001010001010100010101010000010001010100010101000100010
01110111011111011101010111011101110111110111010111010101110111010
01010000010000010101010001010000000100000000010101010000010101010
01010111110111110101010101010111111101110111110101010111110101010

later I want to access every element of the line. I appreciate anyone with hints:

Moshe Slavin
  • 5,127
  • 5
  • 23
  • 38
Wado
  • 23
  • 5

1 Answers1

0

Just do:

with open(file_path, 'rt') as f:
    result = np.array([[ int(c) for c in line ] for line in f ])
OSainz
  • 522
  • 3
  • 6
  • Got this error after running with this code:", line 150, in result = np.array([[int(c) for c in line] for line in ff]) – Wado Jun 17 '19 at 11:58
  • I fixed the error that showed up, thanks for the hint indeed. – Wado Jun 17 '19 at 14:04