Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do zero entries in numpy.array occupy memory?

Suppose I use numpy arrays (e.g. numpy.ndarray) to store large, sparse matrices (i.e., most of the entries are 0): Do the zero entries actually occupy memory? Does numpy support sparse arrays, and if yes, which storage format is used?

like image 891
clstaudt Avatar asked Feb 20 '23 13:02

clstaudt


2 Answers

I think that what you are really looking for is the scipy sparse module, which supports multiple formats.

SCIPY SPARSE DOCUMENTATION http://docs.scipy.org/doc/scipy/reference/sparse.html

The stackoverflow link below gives a great example of using scipy sparse matrices as well. Scipy sparse... arrays?

like image 188
aquil.abdullah Avatar answered Mar 06 '23 05:03

aquil.abdullah


Do the zero entries actually occupy memory?

With ndarray, they do.

There are, however, separate classes in SciPy that support a variety of sparse storage formats. See the documentation.

like image 27
NPE Avatar answered Mar 06 '23 04:03

NPE