How to get the line of a particular Python matrix dice

Asked

Viewed 1,691 times

1

I need through the index of a "column" matrix to access your row completely to be able to make changes in the indexes of this row. The part of collecting the indexes I managed, but I do not know how to access through this chosen index view the line completely.

list1 = [1, 6, 4, 4, 5]

Lista2 = [2, 2, 3, 4, 6]

list3 = [3, 9, 8, 7, 3]

list4 = [4, 7, 3, 8, 0]

matrix = [list1] + [Lista2] + [list3] + [list4]

column = [row[0] for row in matrix]

print(column)

So through the index [0] [1,2,3,4], if I choose 2[3] I need to return the values [9, 8, 7, 3] to then be able to exchange some number, 9 for 5 for example. I hope you were able to explain.

2 answers

2


In the example, I informed the position of line as fixed and then informed the initial position of the spine until the final position:

lista1 = [1, 6, 4, 4, 5]

lista2 = [2, 2, 3, 4, 6]

lista3 = [3, 9, 8, 7, 3]

lista4 = [4, 7, 3, 8, 0]

matriz = [lista1] + [lista2] + [lista3] + [lista4]

colunas = matriz[2][1:5]

print(colunas)  

So you can get only the values of the columns you want, just go changing the positions of the rows and columns to get different values.

I hope I helped you.

More about matrices here.

  • That’s right, there was a variable missing then.

0

I have another question, taking advantage that it is in the same file.

When the user is going to choose a number, example to column 2, internally python will work column 3, I made a test with the code I modified, making the user ask for the column.

list1 = [1, 2, 3, 4, 5]

Lista2 = [2, 2, 3, 4, 6]

list3 = [3, 9, 8, 7, 3]

list4 = [4, 7, 3, 8, 0]

matrix = [list1] + [Lista2] + [list3] + [list4]

number = int(input("type the number: "))

column = [row[number] for row in matrix]

columns = matrix[number][0:5]

columns[1] = 9

print(columns)

I tested the solution I had already found.

list1 = [1, 2, 3, 4, 5]

Lista2 = [2, 2, 3, 4, 6]

list3 = [3, 9, 8, 7, 3]

list4 = [4, 7, 3, 8, 0]

matrix = [list1] + [Lista2] + [list3] + [list4]

column = [row[0]-1 for row in matrix] # -1 type 2 and edit column number 2 1

print(column[3])

But this way of entering the -1 no for did not work in the main code. What remains to function as this second code?

  • An array has Rows and Columns, see the example Matrix[row][column]

  • 1

    I found the error, I needed to insert -1 inside the column bracket >> columns = matrix[number-1][0:5]. Thanks for the help, I just can’t vote on the answer.

Browser other questions tagged

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