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:

1
  • 1
    If you only need hints refer here Commented Jun 17, 2019 at 10:14

1 Answer 1

0

Just do:

with open(file_path, 'rt') as f:
    result = np.array([[ int(c) for c in line ] for line in f ])
Sign up to request clarification or add additional context in comments.

2 Comments

Got this error after running with this code:", line 150, in <module> result = np.array([[int(c) for c in line] for line in ff])
I fixed the error that showed up, thanks for the hint indeed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.