Question: You will be given a matrix A as a nested dictionary and a (densely stored) vector x as a numpy array. You will also be

 You will be given a matrix A as a nested dictionary

You will be given a matrix A as a nested dictionary and a (densely stored) vector x as a numpy array. You will also be given shape, which is a tuple (rows, columns) giving the size of A. Assign the variable Ax to be a numpy array with the contents of the matrix-vector product Ax. The nested dictionary storage for A works as follows: The outermost dictionary maps the row index of the matrix to another, inner dictionary. If a given row of A consists of all zeros, its row index will not be present in the dictionary. The inner, per-row dictionary maps the column index to the value of the actual entry. If a given entry of A is zero, its row dictionary will not contain an entry for it. The matrix A = [0 0 17 31 0 0 0 5 0 0 0 0 0 14 0 0] corresponds to the following Python data structure: A = {0: {2: 17, 3: 31}, 1: {3: 5}, 3: {1: 14}} Your code should do an amount of work proportional to the number of non-zeros entries in A, not proportional to nm, where n times m is the shape of A. (If your code does too much work, we will take off points, even if it does the right thing.) You will be given a matrix A as a nested dictionary and a (densely stored) vector x as a numpy array. You will also be given shape, which is a tuple (rows, columns) giving the size of A. Assign the variable Ax to be a numpy array with the contents of the matrix-vector product Ax. The nested dictionary storage for A works as follows: The outermost dictionary maps the row index of the matrix to another, inner dictionary. If a given row of A consists of all zeros, its row index will not be present in the dictionary. The inner, per-row dictionary maps the column index to the value of the actual entry. If a given entry of A is zero, its row dictionary will not contain an entry for it. The matrix A = [0 0 17 31 0 0 0 5 0 0 0 0 0 14 0 0] corresponds to the following Python data structure: A = {0: {2: 17, 3: 31}, 1: {3: 5}, 3: {1: 14}} Your code should do an amount of work proportional to the number of non-zeros entries in A, not proportional to nm, where n times m is the shape of A. (If your code does too much work, we will take off points, even if it does the right 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!