Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 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
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