|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
||||
|
||||
|
can Python open a matrix saved by Octave in sparse format?
Attached ZIP file contains a 17842x2696 matrix with 53526 non-zero elements stored in Octave sparse format. Can Python load a matrix stored in this format? |
|
#2
|
||||
|
||||
|
Re: can Python open a matrix saved by Octave in sparse format?
do we know the size of the matrix before hand?
|
|
#3
|
||||
|
||||
|
Re: can Python open a matrix saved by Octave in sparse format?
Quote:
|
|
#4
|
||||
|
||||
|
Re: can Python open a matrix saved by Octave in sparse format?
Quote:
Code:
GNU Octave, version 3.6.4
Copyright (C) 2013 John W. Eaton and others.
This is free software; see the source code for copying conditions.
Octave was configured for "i686-pc-mingw32".
Additional information about Octave is available at http://www.octave.org.
+ ## load the alliances design matrix
+ tic;
+ load ('$A.dat');
+ toc
Elapsed time is 0.422 seconds.
+ [alliances, teams] = size (A)
alliances = 17842
teams = 2696
+ matches = alliances / 2
matches = 8921
+ ## convert it to full
+ tic;
+ Af = full (A);
+ toc
Elapsed time is 0.343 seconds.
+ endscript;
|
|
#5
|
||||
|
||||
|
Re: can Python open a matrix saved by Octave in sparse format?
Here's a bit of a quick hack:
Code:
import scipy.sparse import numpy def read_sparse(filename): (r, c, d) = numpy.transpose(numpy.loadtxt(filename, 'int')) return scipy.sparse.coo_matrix((d, (r-1, c-1))) --- A better approach would be to have Octave save the data into MATLAB format (using something like save -6 A_sparse_octave.mat A), then read it in Python using scipy.io.loadmat |
|
#6
|
||||
|
||||
|
Re: can Python open a matrix saved by Octave in sparse format?
Quote:
Do you happen to know where I can find the spec for the Matlab matrix binary storage file format? |
|
#7
|
|||
|
|||
|
Re: can Python open a matrix saved by Octave in sparse format?
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|