This could be done more efficiently with a np.empty and a fill.