Question: Design a Matrix class in Pyhton (WITHOUT using built in functions such as numpy): - add(Matrix M). Tell a matrix to add M to itself
Design a Matrix class in Pyhton (WITHOUT using built in functions such as numpy):
- add(Matrix M). Tell a matrix to add M to itself and return a new matrix containing the result.
- mult(Matrix M). Tell a matrix to multiply itself by M and return a new matrix containing the result.
- scalarMult(float c). Tell a matrix to multiply itself by scalar c and return a new matrix containing the result.
- isZero(). Ask a matrix whether it is the zero matrix; return True if it is and False if not.
- isSquare(). Ask a matrix whether it is a square matrix; return True if is and false if not.
- __init__(rows, cols, elts). This is a so-called "constructor," i.e., a method that initializes a newly created matrix object. Every Python class should have a method with this name to initialize objects. In our case, the constructor has the number of rows and columns in the matrix as arguments, along with a list of the values to place in the matrix. This list is in "row-major order," meaning that it starts with all the elements of the first row, followed by all the elements of the second row, and so forth.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
