Skip to content Skip to sidebar Skip to footer

Numpy.savetxt Indexerror: Tuple Index Out Of Range

I have a numpy array with the following attributes: print(matrix.shape) (30000, 1000) print(matrix) (0, 208) 0.107297742751 (0, 666) 0.107413554001 (0, 833) 0.09048

Solution 1:

From the output of print(matrix), it is apparent that matrix is an instance of scipy.sparse.coo_matrix. Such a matrix is not a numpy array; numpy knows nothing about scipy sparse matrices. In particular, numpy.savetxt doesn't handle scipy's sparse matrices.

For a suggestion on how to save a sparse matrix to a text file, see my answer to a different question here: How to format in numpy savetxt such that zeros are saved only as "0"

Post a Comment for "Numpy.savetxt Indexerror: Tuple Index Out Of Range"