Answered step by step
Verified Expert Solution
Question
1 Approved Answer
The following class named Matrix has a template given to you. The init ( ) method takes 2 parameters. The parameter name is a string,
The following class named Matrix has a template given to you. The init method takes parameters. The parameter name is a string, and the parameter data is a nested list representing a Matrix. Each element in data is a list of elements for that row
For example represents
Modify the class according to the following specifications
Write a method named Average. Matrix.Average should return the average of all values in the matrix as a float. Assume the average of an empty matrix is
Overload the subtraction operator so that you can subtract two matrices from each other. Subtracting Matrices should result in a new matrix. If the matrices are the same side then the result is a new matrix. The new matrix will have the 'Matrixname Matrixname'. The data for the matrix should be element by element subtraction of the second matrix from the first. If the matrices are not the same size, then the method should return the string 'error'.
Overload the addition operator so that if the matrix is added to a value integer or float all values in the matrix increase by that value
Examples
Example Code:
a Matrixa
printa # this should work with the template
Example Output:
a
Example Code:
a Matrixa
avg aAverage
printavg # this should work with the template
Example Output:
Example Code:
a Matrixa
b Matrixb
printprinting ab
printab
Example Output:
printing ab
ab
Example Code:
a Matrixa
a
printa
Example Output:
a
Example Code:
a Matrixa
b Matrixb
printprinting ab
printab
Example Output:
printing ab
error
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started