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
class Matrix:
def initself rows:
initializes a Matrix with given rows
:param rows: the list of rows that this Matrix object has
self.rows rows
self.cols
self.constructcols
return
INSERT MISSING SETTERS AND GETTERS HERE"""
def constructcolsself:
HELPER METHOD: Resets the columns according to the existing rows
self.cols
# FIXME: INSERT YOUR IMPLEMENTATION HERE
return
def constructrowsself:
HELPER METHOD: Resets the rows according to the existing columns
self.rows
# FIXME: INSERT YOUR IMPLEMENTATION HERE
return
def addself 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 subself 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 mulself 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 typeother float or typeother int:
printFIXME: Insert implementation of MATRIXSCALAR multiplication" # FIXME: REPLACE WITH IMPLEMENTATION
elif typeother Matrix:
printFIXME: Insert implementation of MATRIXMATRIX multiplication" # FIXME: REPLACE WITH IMPLEMENTATION
elif typeother Vec:
printFIXME: Insert implementation for MATRIXVECTOR multiplication" # FIXME: REPLACE WITH IMPLEMENTATION
else:
raise TypeErrorfMatrix typeother is not supported."
return
def rmulself 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 typeother float or typeother int:
printFIXME: Insert implementation of SCALARMATRIX multiplication" # FIXME: REPLACE WITH IMPLEMENTATION
else:
raise TypeErrorftypeother Matrix is not supported."
return
ALL METHODS BELOW THIS LINE ARE FULLY IMPLEMENTED
def dimself:
gets the dimensions of the mxn matrix
where m number of rows, n number of columns
:return: tuple type; m n
m lenselfrows
n lenselfcols
return m n
def strself:
prints the rows and columns in matrix form
matstr
for row in self.rows:
matstr strrow
return matstr
def eqself other:
overloads the operator to return True if
two Matrix objects have the same row space and column space
if typeother Matrix:
return False
thisrows roundx for x in self.rows
otherrows roundx for x in other.rows
thiscols roundx for x in self.cols
othercols roundx for x in other.cols
return thisrows otherrows and thiscols othercols
def reqself other:
overloads the operator to return True if
two Matrix objects have the same row space and column space
if typeother Matrix:
return False
thisrows roundx for x in self.rows
otherrows roundx for x inother.rows
thiscols roundx for x in self.cols
othercols roundx for x in other.cols
return thisrows otherrows and thiscols othercols
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
