python generic matrix module