Код: Выделить всё
import polars as pl
import numpy as np
streamflow_data = np.arange(0, 20, 1)
adaptive_alphas = np.concatenate([np.repeat(0.3, 10), np.repeat(0.6, 10)])
streamflow_series = pl.Series(streamflow_data)
ewma_data = np.zeros_like(streamflow_data)
for i in range(1, len(streamflow_series)):
current_alpha = adaptive_alphas[i]
ewma_data[i] = streamflow_series[:i+1].ewm_mean(alpha=current_alpha)[-1]
Код: Выделить всё
# When set dtype of ewma_data to float when initial it, output is like this
Output: [0 0.58823529 1.23287671 1.93051717 2.67678771 3.46668163, 4.29488309 5.1560635 6.04512113 6.95735309 9.33379473 10.33353466, 11.33342058 12.33337091 13.33334944 14.33334021 15.33333625 16.33333457, 17.33333386 18.33333355]
# When I don't point dtype of ewma_data and dtype of streamflow_data is int, output will be floored
Output: [0 0 1 1 2 3 4 5 6 6 9 10 11 12 13 14 15 16 17 18]
И как же это сделать? можно ли погасить в своем коде и не повлиять на его результат?
Надеюсь на ваш ответ.
Подробнее здесь: https://stackoverflow.com/questions/793 ... ating-emwa
Мобильная версия