Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

scipy large sparse matrix

Tags:

python

scipy

I'm trying to use large 10^5x10^5 sparse matrices but seem to be running up against scipy:

n = 10 ** 5
x = scipy.sparse.rand(n, n, .001)

gets

ValueError: Trying to generate a random sparse matrix such as the
    product of dimensions is greater than 2147483647 - this is not
    supported on this machine

Does anyone know why limit is there and if I can avoid it? (fyi, I'm using a macbook air with 4gb memory and the enthought distribution)

like image 402
ericf Avatar asked Feb 15 '26 16:02

ericf


1 Answers

This is a limitation which results from the way scipy.sparse.rand() is implemented. You can roll your own random matrix generation to circumvent this limitation:

n = 10 ** 5
density = 1e-3
ij = numpy.random.randint(n, size=(2, n * n * density))
data = numpy.random.rand(n * n * density)
matrix = scipy.sparse.coo.coo_matrix((data, ij), (n, n))
like image 191
Sven Marnach Avatar answered Feb 18 '26 07:02

Sven Marnach



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!