pythonmatrix

How can I change just one element of a matrix in python?


So, I've created a 7x7 matrix. And I want to change just one element of it, let's say the element on the position of [3][3], but...don't managed to find it out, how to do it properly. If I do it this way, it changes the whole column. How can I do it, to work well? Thx for help!

Here is the code:

for i in range(1, row+1):
    for j in range(1, column+1):
            board.append(0)
            matrix_1.append(board)

matrix_1[3][3]="X"

And here is the output:

0 0 X 0 0 0 0 0
0 0 X 0 0 0 0 0
0 0 X 0 0 0 0 0
0 0 X 0 0 0 0 0
0 0 X 0 0 0 0 0
0 0 X 0 0 0 0 0  
0 0 X 0 0 0 0 0
0 0 X 0 0 0 0 0

Solution

  • hope this will help you

    row=7
    column=7
    matrix_1=[]
    for i in range(1, row+1):
        board=[]
        for j in range(1, column+1):
                board.append(0)
        matrix_1.append(board)
    print(matrix_1)
    
    matrix_1[3][3]="X"
    print(matrix_1)