1
import sys
import numpy as np

a = np.linspace(0, 10, 8, dtype=np.float64)
b = np.linspace(0, 10, 8, dtype=np.float32)
c = np.linspace(0, 10, 8, dtype=np.float16)


print(f'float64 size: {sys.getsizeof(a)} bytes\nfloat32 size: {sys.getsizeof(b)} bytes'
      f'\nfloat16 size: {sys.getsizeof(c)} bytes')

which results the following:

float64 size: 104 bytes

float32 size: 136 bytes

float16 size: 120 bytes

9769953
  • 10,344
  • 3
  • 26
  • 37
BenjamnGC
  • 11
  • 2
  • `linspace` has returned a `view` of an unnamed arrray used during its creation. So `getsizeof` is not a reliable measure of total memory use. Test `a1=a.copy()` etc – hpaulj Sep 20 '21 at 13:26

0 Answers0