significantly improve the performance by adding copy=False to np.matrix calls