Advertisement
Guest User

Untitled

a guest
Dec 23rd, 2020
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. ### header 1
  2. ```python
  3. # Program to multiply two matrices using nested loops
  4.  
  5. # take a 3x3 matrix
  6. A = [[12, 7, 3],
  7. [4, 5, 6],
  8. [7, 8, 9]]
  9.  
  10. # take a 3x4 matrix
  11. B = [[5, 8, 1, 2],
  12. [6, 7, 3, 0],
  13. [4, 5, 9, 1]]
  14.  
  15. result = [[0, 0, 0, 0],
  16. [0, 0, 0, 0],
  17. [0, 0, 0, 0]]
  18.  
  19. # iterating by row of A
  20. for i in range(len(A)):
  21.  
  22. # iterating by coloum by B
  23. for j in range(len(B[0])):
  24.  
  25. # iterating by rows of B
  26. for k in range(len(B)):
  27. result[i][j] += A[i][k] * B[k][j]
  28.  
  29. for r in result:
  30. print(r)
  31.  
  32.  
  33. # Program to multiply two matrices using nested loops
  34.  
  35. # take a 3x3 matrix
  36. A = [[12, 7, 3],
  37. [4, 5, 6],
  38. [7, 8, 9]]
  39.  
  40. # take a 3x4 matrix
  41. B = [[5, 8, 1, 2],
  42. [6, 7, 3, 0],
  43. [4, 5, 9, 1]]
  44.  
  45. result = [[0, 0, 0, 0],
  46. [0, 0, 0, 0],
  47. [0, 0, 0, 0]]
  48.  
  49. # iterating by row of A
  50. for i in range(len(A)):
  51.  
  52. # iterating by coloum by B
  53. for j in range(len(B[0])):
  54.  
  55. # iterating by rows of B
  56. for k in range(len(B)):
  57. result[i][j] += A[i][k] * B[k][j]
  58.  
  59. for r in result:
  60. print(r)
  61. ```
  62. text
  63.  
  64. ```test```
  65. ### header number 2
  66. - test 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement