fork(1) download
  1. def soma_matrizes(m1, m2):
  2. import numpy as np
  3. m1 = np.array(m1)
  4. m2 = np.array(m2)
  5. if m1.shape != m2.shape:
  6. return False
  7. else:
  8. return (m1 + m2).tolist()
  9.  
  10. m1 = [[1, 2, 3],[4, 5, 6]]
  11. m2 = [[2, 3, 4],[5, 6, 7]]
  12. print(soma_matrizes(m1, m2))
  13.  
  14. m1 = [[1], [2], [3]]
  15. m2 = [[2, 3, 4],[5, 6, 7]]
  16. print(soma_matrizes(m1, m2))
Success #stdin #stdout 0.07s 92224KB
stdin
Standard input is empty
stdout
[[3, 5, 7], [9, 11, 13]]
False