0
Hello, I’m making a python algorithm that makes the product between two matrices, but I’m having trouble displaying the resulting matrix
matriz = []
linha = []
linha2= []
matriz_result = []
result = 0
lista = []
nlin,ncol= map(int,input().split())
for i in range(0,nlin):
valor = (input().split())
valor = list(map(int,valor))
linha.append(valor)
matriz.append(linha)
matriz2 = []
nlin2,ncol2 = map(int,input().split())
for i in range(0,nlin2):
valor = (input().split())
valor = list(map(int,valor))
linha2.append(valor)
matriz2.append(linha2)
for i in range(nlin):
if ncol!=nlin2:
print("ERRO")
for j in range(ncol):
for h in range(0,1):
for k in range(ncol):
result += matriz[i][i][k]*matriz2[k][k][i]
matriz_result.append(result)
print(matriz_result)
I have to place the matrix inputs on the same line, there for some reason an element of the matrix is given by three parameters.
Someone tell me what I need to change in the code?
You had not put the [python] tag on your question. Without it, almost no one would find it.
– Victor Stafusa
@Lucas, matrices have 3 dimensions? (expected 2); if you print the value of
matriz
is looking something like[[[0, 1], [1, 0]], [[0, 1], [1, 0]]]
– JJoao