human
Can you provide a code to 4 given the following:
4.  Write a class called Matrix that can be initialized with an iterable of numbers, together with the number of rows r and the number of columns c. That is, you should be able to create a matrix M by calling M =  Matrix([1,2,3,4], 2, 2) (assume the matrix is row ordered). The Matrix class will have a single additional method called at that takes a tuple (r, c) and returns the value at row r and column c. For example, M.at(0,1) will return 2. Internally, the data should be stored as a list and the at method will use indexing to find the right value to return."
Please write code following the instructions in jupyter notebook style.
assistant
#Here is code to 4.

class Matrix:
    """Simple class to represent a matrix."""
    
    def __init__(self, xs, rows, cols):
        self.xs = list(xs)
        self.rows = rows
        self.cols = cols  
            
    def at(self, i, j):
        idx = i*self.cols + j
        return self.xs[idx]

M =  Matrix([1,2,3,4], 2, 2)

M.at(0,1)