fork download
  1. x,y = input("Enter the dimensions as ROWS,COLS:\n")
  2. print
  3.  
  4. m1 = [[0 for i in xrange(y)] for j in xrange(x)] # X*Y
  5. m2 = [[0 for i in xrange(x)] for j in xrange(y)] # Y*X
  6. R = [[0 for i in xrange(x)] for j in xrange(x)] # Result as X*X
  7.  
  8. def enter(m, n, rows, cols):
  9. print "Enter Matrix %d with height %d, width %d one row at a time...\n" % (n,rows,cols)
  10.  
  11. for i in xrange(rows):
  12. m[i] = input("Row %d:" % (i+1)) # input a row like this: [1,2,3,...]
  13. print
  14.  
  15. enter(m1,1,x,y) # enter Matrix 1
  16. enter(m2,2,y,x) # enter Matrix 2
  17.  
  18. for i in xrange(x):
  19. for j in xrange(x):
  20. R[i][j] = sum(m1[i][k] * m2[k][j] for k in xrange(y))
  21.  
  22. for row in R:
  23. print row
Success #stdin #stdout 0.01s 8976KB
stdin
2,3
[1,2,3]
[4,5,6]
[1,2]
[3,4]
[5,6]
stdout
Enter the dimensions as ROWS,COLS:

Enter Matrix 1 with height 2, width 3 one row at a time...

Row 1:Row 2:
Enter Matrix 2 with height 3, width 2 one row at a time...

Row 1:Row 2:Row 3:
[22, 28]
[49, 64]