[英]Determining the byte size of a scipy.sparse matrix?
Is it possible to determine the byte size of a scipy.sparse matrix? 是否可以确定scipy.sparse矩阵的字节大小? In NumPy you can determine the size of an array by doing the following:
在NumPy中,您可以通过执行以下操作来确定数组的大小:
import numpy as np
print(np.zeros((100, 100, 100).nbytes)
8000000
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. 稀疏矩阵由常规numpy数组构成,因此您可以像常规数组一样获取其中任何一个的字节数。
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.