matrix_fun.py version 2