Determining the byte size of a scipy.sparse matrix?

后端 未结 1 1176
走了就别回头了
走了就别回头了 2020-12-30 21:00

Is it possible to determine the byte size of a scipy.sparse matrix? In NumPy you can determine the size of an array by doing the following:

import numpy as n         


        
相关标签:
1条回答
  • 2020-12-30 21:52

    A sparse matrix is constructed from regular numpy arrays, so you can get the byte count for any of these just as you would a regular array.

    If you just want the number of bytes of the array elements:

    >>> from scipy.sparse import csr_matrix
    >>> a = csr_matrix(np.arange(12).reshape((4,3)))
    >>> a.data.nbytes
    88
    

    If you want the byte counts of all arrays required to build the sparse matrix, then I think you want:

    >>> print a.data.nbytes + a.indptr.nbytes + a.indices.nbytes
    152
    
    0 讨论(0)
提交回复
热议问题