首页 > 解决方案 > ValueError:行索引超出矩阵维度稀疏 coo 最大值

问题描述

我真的不知道根本原因是什么!我在下面创建了矩阵并尝试增加(M,N)大小,或减小数据大小或行大小或列大小,甚至将 dtype 从 float32 更改为 float64,但都失败了!我不断收到“行索引超出矩阵尺寸”错误,如果您有任何线索,请帮助,谢谢。

adj = sp.coo_matrix((np.ones(edges.shape[0]), (edges[:, 0],edges[:, 1])),
                      shape=(np.max(node_labels.shape[0])+1, np.max(node_labels.shape[0])+1), dtype=np.float32)

除了,

len(np.ones(edges.shape[0])) = len(edges[:, 0]) = len(edges[:, 1])= 1432000

len(node_labels.shape[0]) = 1432002

np.max(node_labels.shape[0])+1 = 1432003

您可能已经发现,我的“edges”大小比“node_labels”的大小要小得多,为什么我仍然得到行索引超出错误???

标签: pythondataframesparse-matrix

解决方案


我自己解决了这个问题,好吧,事实很残酷,只需要重新编码edges[:, 0])和edges[:, 1]中的值,但是我不知道它会如何影响我的gcn模型,因为我只对 edge.csv 的列进行编码,而使 nodes.csv 保持不变......


推荐阅读