Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Matrix:
- def __init__(self, data): #takes in a double array no matter the size of it.
- self.data = data
- self.rows = len(data) #determines row by number of items in list
- self.cols = len(data[0]) #determines columns by number of items withing list of a list
- self.size = [self.rows, self.cols] #determines how big the matrix is by number of rows and columns
- def multiply(self, other):
- if self.size != other.size:
- return "dimensions are not the same"
- else:
- result = [[0 for i in range(self.cols)] for i in range(self.rows)]
- print(result)
- for i in range(self.rows):
- # iterating by coloum by B
- for j in range(other.cols):
- # iterating by rows of B
- for k in range(other.rows):
- result[i][j] += self.data[i][k] * other.data[k][j]
- print(k)
- return(result)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement