Skip to content

Instantly share code, notes, and snippets.

@dvgodoy
Created October 8, 2022 19:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dvgodoy/7723dbf59835fd15c1a0f3605d73959d to your computer and use it in GitHub Desktop.
Save dvgodoy/7723dbf59835fd15c1a0f3605d73959d to your computer and use it in GitHub Desktop.
def change_evolution(changes, offset=True):
breaks, averages = changes
# Creates a full series using the break points and using the average
# of each regime
avg_series = np.concatenate([[averages[i]] * (breaks[i + 1] - breaks[i])
for i in range(len(averages))])
# If offset, shifts the starting point to zero
if offset:
avg_series -= avg_series[0]
# If the first break is other than zero, concatenates empty data at
# the start to make the array full size
if breaks[0] > 0:
avg_series = np.concatenate([[np.nan] * breaks[0], avg_series])
return avg_series
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment