| 1 |
|
| 2 |
import numpy as np |
| 3 |
import sys |
| 4 |
|
| 5 |
x = np.ones((1, 1)) |
| 6 |
print(sys.getsizeof(x) / 1048576) |
| 7 |
|
| 8 |
x = np.ones((1000, 1000)) |
| 9 |
print(sys.getsizeof(x) / 1048576) |
| 10 |
|
| 11 |
x = np.ones((1000, 2000)) |
| 12 |
print(sys.getsizeof(x) / 1048576) |
| 13 |
|
| 14 |
x = np.ones((1000, 20000)) |
| 15 |
print(sys.getsizeof(x) / 1048576) |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
def allocate(): |
| 20 |
for i in range(100): |
| 21 |
x = np.ones((1000, 1000)) |
| 22 |
x = np.ones((1, 1)) |
| 23 |
x = np.ones((1, 1)) |
| 24 |
x = np.ones((1, 1)) |
| 25 |
x = np.ones((1000, 2000)) |
| 26 |
x = np.ones((1, 1)) |
| 27 |
x = np.ones((1, 1)) |
| 28 |
x = np.ones((1, 1)) |
| 29 |
x = np.ones((1000, 20000)) |
| 30 |
x = 1 |
| 31 |
x += 1 |
| 32 |
x += 1 |
| 33 |
x += 1 |
| 34 |
|
| 35 |
|
| 36 |
allocate() |