Advertisement
Guest User

Untitled

a guest
Sep 29th, 2018
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.00 KB | None | 0 0
  1. class Matrix:
  2.  
  3.     def __init__(self, data): #takes in a double array no matter the size of it.
  4.         self.data = data
  5.         self.rows = len(data) #determines row by number of items in list
  6.         self.cols = len(data[0]) #determines columns by number of items withing list of a list
  7.         self.size = [self.rows, self.cols] #determines how big the matrix is by number of rows and columns
  8.  
  9.  
  10.     def multiply(self, other):
  11.  
  12.         if self.size != other.size:
  13.             return "dimensions are not the same"
  14.         else:
  15.             result = [[0 for i in range(self.cols)] for i in range(self.rows)]
  16.             print(result)
  17.  
  18.  
  19.             for i in range(self.rows):
  20.  
  21.                 # iterating by coloum by B
  22.                 for j in range(other.cols):
  23.  
  24.                     # iterating by rows of B
  25.                     for k in range(other.rows):
  26.  
  27.                         result[i][j] += self.data[i][k] * other.data[k][j]
  28.                         print(k)
  29.  
  30.         return(result)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement