I coded a two-dimensional symmetric matrix with Python. However, the result value does not keep coming out of the situation I want. I think my code can make a symmetric matrix perfectly, but I don't know why there are other results. Below is the Python code.
import random
inputN = random.randrange(1, 10)
inputArr= [[0]*inputN]*inputN
for i in range(0, inputN):
for j in range(i, inputN):
if i != j:
Rvalue = random.randrange(0, 11)
inputArr[i][j] = Rvalue
inputArr[j][i] = Rvalue
print(inputN)
for i in range(0, inputN):
for j in range(0, inputN):
print(inputArr[i][j], end=" ")
print("")
Below is the output value.
6
8 3 6 2 8 8
8 3 6 2 8 8
8 3 6 2 8 8
8 3 6 2 8 8
8 3 6 2 8 8
8 3 6 2 8 8
Aucun commentaire:
Enregistrer un commentaire