python ValueError:列索引超出矩阵维度

时间:2016-06-21 08:34:56

标签: python-2.7 numpy scipy

我正在使用我的文件运行一个简单的python程序。这个程序在我的一台机器上使用fileA.bed文件正常工作。但是这个程序在具有相同文件的另一台机器上不起作用。我安装了相同的python版本,2.7.6,相同的必需模块,scipy('0.15.1'),numpy('1.8.2'),iced('0.2.2-git')(两台机器中的版本相同)。错误消息与ValueError: column index exceeds matrix dimensions有关(请参阅下文)。你能帮忙,可能导致这个问题吗?

python Dense.py -b fileA.bed 

Traceback (most recent call last):
  File "Dense.py", line 34, in <module>
    counts = io.load_counts(args.filename, lengths=lengths)
  File "$PATH/Python-2.7.6/venv_iced_2.2/lib/python2.7/site-packages/iced/io/_io_else.py", line 30, in load_counts
    counts = sparse.coo_matrix((X[:, 2], (X[:, 0], X[:, 1])), shape=shape)
  File "$PATH/Python-2.7.6/venv_iced_2.2/lib/python2.7/site-packages/scipy/sparse/coo.py", line 206, in __init__
    self._check()
  File "$PATH/Python-2.7.6/venv_iced_2.2/lib/python2.7/site-packages/scipy/sparse/coo.py", line 262, in _check
    raise ValueError('column index exceeds matrix dimensions')
ValueError: column index exceeds matrix dimensions

1 个答案:

答案 0 :(得分:3)

我可以通过创建sparse.coo_matrix来重现此错误:

In [1075]: sparse.coo_matrix(([1,1,1],([0,1,1],[0,1,3])), shape=(2,3))
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-1075-40a6338a3244> in <module>()
----> 1 sparse.coo_matrix(([1,1,1],([0,1,1],[0,1,3])), shape=(2,3))

/usr/lib/python3/dist-packages/scipy/sparse/coo.py in __init__(self, arg1, shape, dtype, copy)
    180             self.data = self.data.astype(dtype)
    181 
--> 182         self._check()
    183 
    184     def getnnz(self, axis=None):

/usr/lib/python3/dist-packages/scipy/sparse/coo.py in _check(self)
    236                 raise ValueError('row index exceeds matrix dimensions')
    237             if self.col.max() >= self.shape[1]:
--> 238                 raise ValueError('column index exceeds matrix dimensions')
    239             if self.row.min() < 0:
    240                 raise ValueError('negative row index found')

ValueError: column index exceeds matrix dimensions

我告诉它矩阵应该是2x3,但其中一个列值是3,其中它应该在[0,3]范围内(小于3)。

我对您的iced软件包或文件中显然正在尝试加载的数据一无所知。但希望这可以让您了解在哪里搜索问题。