w3resource

NumPy: Get the memory usage by NumPy arrays

NumPy: Array Object Exercise-112 with Solution

Write a NumPy program to get the memory usage by NumPy arrays.

Sample Solution:

Python Code:

import numpy as np
from sys import getsizeof
x = [0] * 1024
y = np.array(x)
print(getsizeof(x))

Sample Output:

8256

Python Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a NumPy program to create a Cartesian product of two arrays into single array of 2D points.
Next: Write a NumPy program to build an array of all combinations of three NumPy arrays.

What is the difficulty level of this exercise?

Test your Python skills with w3resource's quiz



Python: Tips of the Day

Set comprehension:

>>> m = {x ** 2 for x in range(5)}
>>> m
{0, 1, 4, 9, 16}