Jump to content

2d matrix values


riad

Recommended Posts

I have a 2-dimensional matrix, initialized to matrix_height [['-'] * 10] * 10
I replace certain boxes so as to have (visually) this:

['A', 'A', 'A', 'A', '-', '-', '-', '-', '-', '-']
['A', 'A', 'A', 'A', '-', '-', '-', '-', '-', '-']
['A', 'A', 'A', 'A', '-', '-', '-', '-', '-', '-']
['A', 'A', 'A', 'A', '-', '-', '-', '-', '-', '-']
['A', 'A', 'A', 'A', '-', '-', '-', '-', '-', '-']
['A', 'A', 'A', 'A', '-', '-', '-', '-', '-', '-']
['A', 'A', 'A', 'A', '-', '-', '-', '-', '-', '-']
['A', 'A', 'A', 'A', '-', '-', '-', '-', '-', '-']
['-', '-', '-', '-', '-', '-', '-', '-', '-', '-']
['-', '-', '-', '-', '-', '-', '-', '-', '-', '-']

when i access tu th value matrix_height[8][0] it gives me : '-'
and it's true for all des values accessing individually (and it's that values that i want).

whene I print the entire line, matrix_height[8], it gives me that :
['A', 'A', 'A', 'A', '-', '-', '-', '-', '-', '-']

can anyone help me ?

thank you

 

matrice_hauteur = [['-']*10]*10
matrice_largeur = [['-']*10]*10

d_d=0
d_c=0
x=8
y=4
print(x,y)
print('rr',matrice_hauteur[7:9],d_c)
for d_d in range(0,x):
    for d_c in range(0,y):
        matrice_hauteur[d_d][d_c]='A'
        print(d_d,d_c)
        if d_c==y:
            break
    if d_d==x:
        break


for d_d in range(0,10):
    for d_c in range(0,10):
        print(matrice_hauteur[d_d-d_c])

print(matrice_hauteur[0-9])
print(matrice_hauteur[1-9])
print(matrice_hauteur[2-9])
print(matrice_hauteur[3-9])
print(matrice_hauteur[4-9])
print(matrice_hauteur[5-9])
print(matrice_hauteur[6-9])
print(matrice_hauteur[7][0],matrice_hauteur[7][1],
matrice_hauteur[7][2],matrice_hauteur[7][3],
matrice_hauteur[7][4],matrice_hauteur[7][5],
matrice_hauteur[7][6],matrice_hauteur[7][7],
matrice_hauteur[7][8],matrice_hauteur[7][9]),
print(matrice_hauteur[8][0],matrice_hauteur[8][1],
matrice_hauteur[8][2],matrice_hauteur[8][3],
matrice_hauteur[8][4],matrice_hauteur[8][5],
matrice_hauteur[8][6],matrice_hauteur[8][7],
matrice_hauteur[8][8],matrice_hauteur[8][9]),
print(matrice_hauteur[9-9])

print(matrice_hauteur[8][4])
print(matrice_hauteur[8])

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...