Added helper functions to matrix.py.