Created
October 8, 2022 19:51
-
-
Save dvgodoy/7723dbf59835fd15c1a0f3605d73959d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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