csv - numpy.savetxt IndexError: tuple index out of range -


i have numpy array following attributes:

print(matrix.shape) (30000, 1000)  print(matrix) (0, 208)      0.107297742751 (0, 666)      0.107413554001 (0, 833)      0.090485141939 (0, 616)      0.090485141939 .. .. 

when try write array file get:

numpy.savetxt('matrix.csv', matrix, delimiter=',') --------------------------------------------------------------------------- indexerror                                traceback (most recent call last) <ipython-input-18-412b5d26d905> in <module>() ----> 1 numpy.savetxt('matrix.csv', matrix, delimiter=',')  c:\anaconda3\lib\site-packages\numpy\lib\npyio.py in savetxt(fname, x, fmt, delimiter, newline, header, footer, comments)    1042                 ncol = len(x.dtype.descr)    1043         else: -> 1044             ncol = x.shape[1]    1045     1046         iscomplex_x = np.iscomplexobj(x)  indexerror: tuple index out of range 

what doing wrong?

from output of print(matrix), apparent matrix instance of scipy.sparse.coo_matrix. such matrix not numpy array; numpy knows nothing scipy sparse matrices. in particular, numpy.savetxt doesn't handle scipy's sparse matrices.

for suggestion on how save sparse matrix text file, see answer different question here: how format in numpy savetxt such zeros saved "0"


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -