SHARE
TWEET

Untitled

a guest Jun 17th, 2019 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def sum_matrix (matrix):
  2.     #
  3.     # | 1 2 3 |
  4.     # | 1 2 3 |
  5.     # | 1 2 3 |  ->  |4 8 12|
  6.     # | 1 2 3 |
  7.     # _________
  8.     #   4 8 12
  9.     vektor = [[0] for i in range(0,len(matrix[0]))]
  10.     for j  in range(0, len(matrix[0])):        #rows 0-3 4
  11.         buffer = 0
  12.         for i in range(0, len(matrix)):  #columns 3
  13.             if matrix[i][j] !=None:
  14.                 buffer = buffer + matrix[i][j]
  15.                 #vektor[j][0] = buffer
  16.             elif matrix[i][j] ==None:
  17.                 vektor[j][0] = None
  18.         vektor[j][0] = buffer
  19.     return vektor
  20.  
  21. print (sum_matrix ([[0,0,0],[0,0,1],[0,1,0],[0,0,0]]))
  22. print (sum_matrix ([[0,0,0],[0,None,1],[0,1,None],[0,0,0]]))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top