Improved computation speed by using lil_matrix