Use sparse matrix

Switch linalg package to use sparse matrices.  

Improve efficiency in to_scipy_sparse_matrix

Addresses #969 and #913