Advertisement
Guest User

Untitled

a guest
Sep 29th, 2018
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.88 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.         result = [[]]
  12.         if self.size != other.size:
  13.             return "dimensions are not the same"
  14.         else:
  15.             for i in range(self.rows):
  16.  
  17.                 # iterating by coloum by B
  18.                 for j in range(other.cols):
  19.  
  20.                     # iterating by rows of B
  21.                     for k in range(other.rows):
  22.  
  23.                         result[i][j] += self.data[i][k] * other.data[k][j]
  24.  
  25.             return(result)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement