A sparse matrix is a representation of a matrix where only the locations of values not equal to the default (usually 0) are stored in memory. A simple way to represent such a matrix in Python is to use a dictionary where the key is a tuple of coordinate (x, y)
and the value is the matrix values.
For example, this matrix:
0 0 0 0
0 0 0 0
0 1 0 0
0 0 0 0
could have the following representation:
matrix = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 1, 0, 0], [0, 0, 0, 0]]
sparse_matrix = {(1, 2): 1}
and you would access the values like that:
for x in xrange(4):
for y in xrange(4):
assert matrix[y][x] == sparse_matrix.get((x, y), 0)
This should be enough to get you started. Your exercise want you to wrap such a sparse matrix in a class that will give it the same interface as a traditional matrix.
There are more advanced way to store such sparse matrix, each doing a different trade off between complexity, memory usage, ...