Saving sparse matrix

I would just save nonzero indexes and values as CSV:

using SparseArrays, DataFrames, CSV
M = sprand(10, 10, 0.2)
I, J, V = findnz(M)
df = DataFrame([:I => I, :J => J, :V => V])
CSV.write("/tmp/spmatrix.csv", df)
5 Likes