change dense to sparse matrix