2
我有一個具有以下屬性的numpy的數組:numpy.savetxt IndexError:元組索引超出範圍
print(matrix.shape)
(30000, 1000)
print(matrix)
(0, 208) 0.107297742751
(0, 666) 0.107413554001
(0, 833) 0.090485141939
(0, 616) 0.090485141939
..
..
當我嘗試寫數組到一個文件中,我得到:
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
我究竟做錯了什麼?
相關:http://stackoverflow.com/questions/15881817/numpy-save- an-array-of-different-types-to-a-text-file – xnx 2014-12-06 02:28:30
如果答案在那裏,我看不到它。 – JeffR 2014-12-06 03:30:38