[Numpy-discussion] Update on sparse matrix in binary
Thu Feb 15 12:48:39 CST 2007
I wanted to thank all of you who helped me with my making my sparse
matrix representation cross-platform in binary format!
I ended up writing and reading everything explicitly in little endian.
To recap, each row in the matrix is represented by three records:
1) row#, nn (number of non-zero elements)
2) col (indices of non-zero elements in row #)
3) values (doubles corresponding to indices provided in the
I created the arrays using:
a = array([values], '<l or d').tostring(); f.write(a)
And read using:
a = f.read(# of bytes, 8 for first record, nn*4 for longs, nn*8 for
a = fromstring(a, '<l or d')
The tofile() and fromfile() version work as well, but it wasn't any
faster. So I went with what I thought was more intuitive in the context
of the algorithm.
So far, it has worked on the Windows, Linux, Solaris and Mac OSX boxes I
have tried. I know it is hardware specific as opposed to platform, so I
will continue to seek out the rarer vintages of machines that can run
the software we provide.
Again, thanks to all; and if there are any more suggestions as to how
this process could be more optimized, please feel free to respond. Best
380 New York St.
Redlands, CA 92373
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Numpy-discussion