[SciPy-user] scipy.sparse: read file

Uwe Schmitt rocksportrocker@googlemail....
Wed Nov 12 07:11:33 CST 2008


I found a solution:


    fp = file(...)

    fp.next()
    num_data = int(fp.next())

    data = zeros((num_data,), dtype=....)
    ij   = zeros((2, num_data), dtype=int)

    for k, row in enumerate(fp):
        i, j, val = row.split()

        ij[0, k] =  int(i)
        ij[1, k] =  int(j)
        data[k]  =  float(val)

    mat = csc_matrix((data, ij))

Greetings, Uwe

On 12 Nov., 13:37, Uwe Schmitt <rocksportroc...@googlemail.com> wrote:
> Hi,
>
> I discovered the save-method which writes a sparse matrix to a file.
> How can construct a sparse matrix from such a file ? I found no
> appropriate
> method.
>
> Greetings, Uwe
> _______________________________________________
> SciPy-user mailing list
> SciPy-u...@scipy.orghttp://projects.scipy.org/mailman/listinfo/scipy-user


More information about the SciPy-user mailing list