Skip to content
Advertisement

Initialize high dimensional sparse matrix

I want to initialize 300,000 x 300,0000 sparse matrix using sklearn, but it requires memory as if it was not sparse:

JavaScript

it gives the error:

JavaScript

which is the same error as if I initialize using numpy:

JavaScript

Even when I go to a very low density, it reproduces the error:

JavaScript

Is there a more memory-efficient way to create such a sparse matrix?

Advertisement

Answer

Just generate only what you need.

JavaScript

This lets you build monster sparse arrays provided they’re sparse enough to fit into memory.

JavaScript

This is probably how the sparse.rand constructor should be working anyway. If any row, col pairs collide it’ll add the data values together, which is probably fine for all applications I can think of.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement