Matrix input reading in python

Asked

Viewed 86 times

0

I’m wondering how to create an array in python, but the input would be the whole matrix. I tried to make:

matrix=[]
for r in range(5):
    row=[]
    for c in range(5):
        row.append(input().split())
    matrix.append(row)

But still error and can not read the input below:

0 0 0 0 0
0 0 0 0 1
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0

What would be the best way to read her whole without using numpy and panda??

1 answer

1

As you are already reporting the entire line in one input, you will not need two loops of repeats, only one, running the number of times referring to the number of rows of the matrix:

matrix=[]
for r in range(5):
    matrix.append(input().split())
  • worked, thank you very much

Browser other questions tagged

You are not signed in. Login or sign up in order to post.