import numpy as np import time as tm odd = np.array([]) value = 0 t = tm.time() for i in range(0, 100000, 1): value = 2*i+1 odd = np.append(odd, value) elapsed1 = tm.time() - t print('Without preallocation:', elapsed1) odd = np.zeros([100000]) value = 0 t = tm.time() for i in range(0, 100000, 1): value = 2*i+1 odd[i] = value elapsed2 = tm.time() - t print('With preallocation:', elapsed2)