[SciPy-User] saving a sparse matrix to file
Thu Jun 28 19:41:16 CDT 2012
If you want to share sparse matrices across different applications a
good bet is the matrix market file format. Most sparse matrix
processing software will accept it.
There are examples here
But do note that its a ascii file format so the output file can be
long and can take a while to read or write.
We have used it and it worked great.
On some of the larger files however the writing was taking close to an
hour, so we sped it up by using multiprocessing to write different
parts of it. But becuse we needed only limited subset of all features
provided by the matrix market format our code only handles that
restricted subset and wont be generally useful.
On Mon, Jun 25, 2012 at 1:34 PM, Pengkui Luo <firstname.lastname@example.org> wrote:
> Is there a unified API to save a sparse matrix of any type (dok, lil, csc,
> ...) to file, as simple as pickle dump/load?
> e.g. Can I do something like the following?
> import numpy as np
> from scipy.sparse import dok_matrix
> from scipy.io import save, load
> mat = dok_matrix (np.zeros ((80000, 80000)), np.int)
> save (file ('foobar.mat', 'wb'), mat) # or mat.save ('foobar.mat')
> mat2 = load (file ('foobar.mat'))
> It seems that there was a .save method for a sparse matrix several years
> ago, but was later deprecated. Why?
> I came across this email response stating that for csr_matrix one can
> save.data, .indices, and .indptr attributes individually to three different
> files and load them all to reassemble the matrix. Is it a hack only suitable
> for csr_matrix, or one that can be applied to all types of sparse matrices?
> Can I save a matrix to a single file instead of three?
> I also came across the scipy.io.savemat API, but had no idea how to use
> it.... What does "mdict : Dictionary from which to save matfile variables."
> mean? What is this dict for? Can someone provide an example on how to use
> SciPy-User mailing list
More information about the SciPy-User