Sparse Matrix ValueError: row index exceeds matrix dimensions

Viewed 5191

I have a sparse matrix in the form of (inl, outl, 1) that I want to convert into a nxn matrix (value is 1 if there is a link between a and b).

However there are multiple b values for each a, which I believe is why the ValueError message is popping up. I've tried csr, coo, csc, bsr matrixes, to no avail...

M = coo_matrix( (yn, (inl,outl)), shape=(n,n) ).toarray()

ValueError: 'row index exceeds matrix dimensions'

Any help is greatly appreciated. Thanks!

1 Answers

I have tried to get the global max from both the intl and outl and it works for me. The code is as follows:

n = max(max(intl), max(outl)) + 1

I hope this would help!

Related