[python] hello

Viewer

  1.  
  2. def nBySixMatrix(a):
  3.     rows = len(a)
  4.     b = [[3,0,0,0,0,0],
  5.          [0,0.5,0,0,0,0],
  6.          [0,0,1, 2,0,0],
  7.          [0,0,3,-1,0,0],
  8.          [0,0,0, 0,0,1],
  9.          [0,0,0,0,1,0]]
  10.     cols = len(b[0])
  11.     temp = [[0 for i in range(cols)] for j in range(rows)]
  12.     for row in range(len(a)):
  13.         for col in range(len(b[0])):
  14.             for k in range(len(b)):
  15.                 if 
  16.                 if(a[row][k] != 0 and b[k][col] != 0):
  17.                     print("thishappened")
  18.                     temp[row][col] += a[row][k] * b[k][col]
  19.                 
  20.  
  21.     return temp
  22.     
  23. #Test Case 1:
  24. test1 = [[1,0,4,2,1,0]]
  25. answer1 = [[3,0,10,6,0,1]]
  26.  
  27. #Test Case 2:
  28. test2 = [[1,2,3,4,5,6],
  29.          [0,1,3,2,4,-1],
  30.          [2,3,0,-3,3,4]]
  31. answer = [[3,1,15,2,6,5],
  32.           [0,0.5,9,4,-1,4],
  33.           [6,1.5,-9,3,4,3]]
  34. print(nBySixMatrix(test1) == answer1)
  35. print(nBySixMatrix(test2) == answer)

Editor

You can edit this paste and save as new:


File Description
  • hello
  • Paste Code
  • 01 Mar-2021
  • 932 Bytes
You can Share it: