Question: Please help me solve this problem by fix these below codes: from Vec import Vec - - - - - - -

Please help me solve this problem by fix these below codes:
from Vec import Vec
"""----------- PROBLEM 1-----------"""
class Matrix:
def __init__(self, rows):
"""initializes a Matrix with given rows
:param rows: the list of rows that this Matrix object has
"""
self.rows = rows
self.cols =[]
self._construct_cols()
return
"""INSERT MISSING SETTERS AND GETTERS HERE"""
def _construct_cols(self):
"""HELPER METHOD: Resets the columns according to the existing rows
"""
self.cols =[]
# FIXME: INSERT YOUR IMPLEMENTATION HERE
return
def _construct_rows(self):
"""HELPER METHOD: Resets the rows according to the existing columns
"""
self.rows =[]
# FIXME: INSERT YOUR IMPLEMENTATION HERE
return
def __add__(self, other):
"""overloads the + operator to support Matrix + Matrix
:param other: the other Matrix object
:raises: ValueError if the Matrix objects have mismatching dimensions
:raises: TypeError if other is not of Matrix type
:return: Matrix type; the Matrix object resulting from the Matrix + Matrix operation
"""
pass # FIXME: REPLACE WITH IMPLEMENTATION
def __sub__(self, other):
"""overloads the - operator to support Matrix - Matrix
:param other:
:raises: ValueError if the Matrix objects have mismatching dimensions
:raises: TypeError if other is not of Matrix type
:return: Matrix type; the Matrix object resulting from Matrix - Matrix operation
"""
pass # FIXME: REPLACE WITH IMPLEMENTATION
def __mul__(self, other):
"""overloads the * operator to support
- Matrix * Matrix
- Matrix * Vec
- Matrix * float
- Matrix * int
:param other: the other Matrix object
:raises: ValueError if the Matrix objects have mismatching dimensions
:raises: TypeError if other is not of Matrix type
:return: Matrix type; the Matrix object resulting from the Matrix + Matrix operation
"""
if type(other)== float or type(other)== int:
print("FIXME: Insert implementation of MATRIX-SCALAR multiplication") # FIXME: REPLACE WITH IMPLEMENTATION
elif type(other)== Matrix:
print("FIXME: Insert implementation of MATRIX-MATRIX multiplication") # FIXME: REPLACE WITH IMPLEMENTATION
elif type(other)== Vec:
print("FIXME: Insert implementation for MATRIX-VECTOR multiplication" ) # FIXME: REPLACE WITH IMPLEMENTATION
else:
raise TypeError(f"Matrix *{type(other)} is not supported.")
return
def __rmul__(self, other):
"""overloads the * operator to support
- float * Matrix
- int * Matrix
:param other: the other Matrix object
:raises: ValueError if the Matrix objects have mismatching dimensions
:raises: TypeError if other is not of Matrix type
:return: Matrix type; the Matrix object resulting from the Matrix + Matrix operation
"""
if type(other)== float or type(other)== int:
print("FIXME: Insert implementation of SCALAR-MATRIX multiplication" ) # FIXME: REPLACE WITH IMPLEMENTATION
else:
raise TypeError(f"{type(other)}* Matrix is not supported.")
return
'''- ALL METHODS BELOW THIS LINE ARE FULLY IMPLEMENTED -'''
def dim(self):
"""gets the dimensions of the mxn matrix
where m = number of rows, n = number of columns
:return: tuple type; (m, n)
"""
m = len(self.rows)
n = len(self.cols)
return (m, n)
def __str__(self):
"""prints the rows and columns in matrix form """
mat_str =""
for row in self.rows:
mat_str += str(row)+"
"
return mat_str
def __eq__(self, other):
"""overloads the == operator to return True if
two Matrix objects have the same row space and column space
"""
if type(other)!= Matrix:
return False
this_rows =[round(x,3) for x in self.rows]
other_rows =[round(x,3) for x in other.rows]
this_cols =[round(x,3) for x in self.cols]
other_cols =[round(x,3) for x in other.cols]
return this_rows == other_rows and this_cols == other_cols
def __req__(self, other):
"""overloads the == operator to return True if
two Matrix objects have the same row space and column space
"""
if type(other)!= Matrix:
return False
this_rows =[round(x,3) for x in self.rows]
other_rows =[round(x,3) for x inother.rows]
this_cols =[round(x,3) for x in self.cols]
other_cols =[round(x,3) for x in other.cols]
return this_rows == other_rows and this_cols == other_cols
Please help me solve this problem by fix these

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Accounting Questions!