Question
Write a class SparseMatrix with an __init__ method which uses a numpy.array matrix as input and which generates an internal representation of the matrix in
Write a class SparseMatrix with an __init__ method which uses a numpy.array matrix as input and which generates an internal representation of the matrix in CSR form. Furthermore it should set an attribute intern_represent to the value CSR.
Furthermore the __init__ method should create an attribute number_of_nonzero reporting the number of nonzero elements
Give the class a method, which allows to change a particular element in the matrix. It should have the elements indexes i, j and its value aij as input. If it changes the numbers of nonzero elements it should change the attribute number_of_nonzero accordingly.
Give the class a method changing the internal representation from CSR to CSC. Dont forget to also change the attribute intern_represent.
Extend your __init__ method by an extra parameter Tol which serves as a threshold for converting a given matrix to a sparse matrix. All elements of the original matrix which have an absolute value less than Tol should be considered as zeros. Give Tol a default value 0.
Write a method for elementwise addition of two objects of type SparseMatrix.
Write a method which multiplies a SparseMatrix with a numpy.array of rank one (i.e. a vector).
The last three lines are the important thing.
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