Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Code in Python!!!! A Matrix class can be used to perform some of the operations found in linear algebra, such as matrix arithmetic. Develop a

Code in Python!!!! A Matrix class can be used to perform some of the operations found in linear algebra, such as matrix arithmetic.

Develop a Matrix class that uses the built-in operators for arithmetic.

In the matrix.py file, complete the following:

Define the Matrix class and extend the Grid class.

Complete the implementation of the following methods:

__init__

__add__, adds two matrices together.

Returns the sum of self and other.

__sub__, subtracts two matrices.

Returns the difference of self and other.

__mul__, multiplies two matrices together.

Returns the product of self and other.

If two matrices cannot be multiplied, raise an Exception.

To test your program run the main() method in the matrix.py file.

Your program's output should look like the following:

6 6 6 6 6 6 6 6 6 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 24 24 24 24

image text in transcribed

image text in transcribed

image text in transcribed

grid.py matrix.py File: grid.py from arrays import Array class Grid(object):1 " Represents a two-dimensional array." self.data = Array(rows) for row in range(rows): self.data [ row ]= Array(columns, fillValue) def getHeight (self): " "Returns the number of rows."\| return len(self.data) def getWidth ( self ) : "Returns the number of columns." return len (selfdata[]) def _-getitem_--(self, index ) : "Supports two-dimensional indexing with [][]. return self.data [index ] def __str__(self): " Returns a string representation of the grid."\| result = " for row in range(self.getHeight ()): for col in range(self.getwidth( )): result +=str(selfdata[row][col])+ result += " " return result def main( ): g=Grid(10,10,1) print (g) if __-name ___==" "main__-" : main()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Focus On Geodatabases In ArcGIS Pro

Authors: David W. Allen

1st Edition

1589484452, 978-1589484450

More Books

Students also viewed these Databases questions