Alex Rivera | Logout

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

Asked 2009-02-19T03:27:34.400
42

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 [1]: a = range(10000)
In [2]: %memusage a
Out[2]: 1MB

Something like %memusage <object> and return the memory used by the object.

Duplicate

Find out how much memory is being used by an object in Python

Edit
Report

1 Answer

25

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
answered 2013-03-23T19:30:46.750

Your Answer