Advertisement
santiagol26

producto de matrices

Apr 26th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.56 KB | None | 0 0
  1. a=[[1,3,5],[2,4,8],[8,4,7]]
  2. b=[[4,9,3],[7,4,3],[5,2,1]]
  3. matriz=[[0,0,0],[0,0,0],[0,0,0]]
  4. numeros=[]
  5. count=0
  6. j=0
  7. m=0
  8. while j<len(a)*len(b):
  9.     sum=0
  10.     for i in range (0, len(a)):
  11.         sum+=a[m][i]*b[i][count]
  12.     if j==2 :
  13.        m+=1
  14.     if j==5:
  15.        m+=1
  16.     count+=1
  17.     if count>=3 :
  18.        count=0
  19.     numeros.append(sum)
  20.     j+=1        
  21. cont=0
  22. for j in range(0,len(a)):
  23.     for m in range(0,len(b)):
  24.         matriz[j][m]=numeros[cont]
  25.         cont+=1
  26. print("multiplicarlas matrices \n A",a,"\n","y B",b,"\n","es igual a",matriz)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement