How can I check the memory usage of objects in iPython?

前端 未结 4 469
萌比男神i
萌比男神i 2020-12-01 04:21

I am using iPython to run my code. I wonder if there is any module or command which would allow me to check the memory usage of an object. For instance:

In [         


        
4条回答
  •  忘掉有多难
    2020-12-01 04:57

    If you are using a numpy array, then you can use the attribute ndarray.nbytes to evaluate its size in memory:

    from pylab import *   
    d = array([2,3,4,5])   
    d.nbytes
    #Output: 32
    

提交回复
热议问题