Dump sparse matrix to file

I have a scipy.sparse.csr matrix and you want to dump it into a CSV file. Is there a way to save the sparseness of the matrix and write it to CSV?

+6
source share
1 answer

SciPy includes functions that read / write sparse matrices in MatrixMarket format using scipy.io module , including mmwrite: http://docs.scipy.org/doc/scipy/reference/generated/scipy.io.mmwrite.html

MatrixMarket is not CSV, but close. It consists of a single-line header C # rows, #cols, # non-zero values, followed by one line for a non-zero value. Each of these rows is a row index, column index, value. You can write a simple script that turns spaces into commas and you will have CSV.

+8
source

Source: https://habr.com/ru/post/888754/


All Articles