此问题已在此处有答案:
How do I determine the size of an object in Python?(16个答案)
Size of a Python list in memory(4个答案)
4天前关闭。
我想知道一个变量占用了多少内存。
让我们假设这个例子:
import numpy as np
t = [np.random.rand(10000) for _ in range(1000)]
t
占用多少兆内存?
我跑过去:sys.getsizeof(array_list)
我得到的是8856
,相对于t
中包含的信息量,它似乎很低
最好的问候。
3条答案
按热度按时间6g8kf2rb1#
链接:https://pypi.org/project/Pympler/
1zmg4dgp2#
我想这(不求助于外部库)可以做到这一点:
nzk0hqpo3#
简答:
sys.getsizeof(variable)
示例:
Full answer