I know in python it’s hard to see the memory usage of an object.
Is it easier to do this for SciPy objects (for example, sparse matrix)?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
you can use array.itemsize (size of the contained type in bytes) and array.flat to obtain the lenght:
it’s not the exact value, as it ignore the whole array infrastructure, but for big array it’s the value that matter (and I guess that you care because you have something big)
if you want to use it on a sparse array you have to modify it, as the sparse doesn’t have the itemsize attribute. You have to access the dtype and get the itemsize from it:
In general I don’t think it’s easy to evaluate the real memory occupied by a python object…the numpy array is an exception being just a thin layer over a C array