【问题标题】:python ValueError: column index exceeds matrix dimensionspython ValueError:列索引超出矩阵维度
【发布时间】:2016-06-24 03:25:19
【问题描述】:

我正在使用我的文件运行一个简单的 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

【问题讨论】:

    标签: python-2.7 numpy scipy


    【解决方案1】:

    我可以通过创建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 包或它显然试图加载的文件中的数据一无所知。但希望这能让您了解在哪里搜索问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多