确定scipy.sparse矩阵的字节大小? [英] Determining the byte size of a scipy.sparse matrix?
本文介绍了确定scipy.sparse矩阵的字节大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以确定scipy.sparse矩阵的字节大小?在NumPy中,您可以通过执行以下操作来确定数组的大小:
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 np
print(np.zeros((100, 100, 100).nbytes)
8000000
推荐答案
稀疏矩阵是由常规numpy数组构成的,因此您可以像对常规数组那样获取其中任何一个的字节数.
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
这篇关于确定scipy.sparse矩阵的字节大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文