I'm trying to output a numpy ndarray as a CSR file (this is an intermediate stage, I'm trying to use a program that requires CSR format as input).
So far, I've tried using scipy.sparse.coo_matrix()
and writing out to an ijv file with the following code:
pca_coo = scipy.sparse.coo_matrix(pca_result)
with open(project + '/matrix/for_knn.jiv', 'w') as f:
for row, col, val in zip(pca_coo.row, pca_coo.col, pca_coo.data):
t= f.write("{}\t{}\t{}\n".format(row, col, val))
The file produced by the above code causes the program downstream to segfault.
I'm assuming at this point that the problem is in the format of the output, but I haven't been able to locate the issue.
Edit: Answered below.