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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!