-
MM们
您是否正在将Covid-19感染时间加倍?请仔细检查结果。我忘了你正在使用熊猫,所以你可能需要这个:y = df['val'].to_numpy()这是第一次拍摄:import numpy as npfrom scipy.interpolate import interp1dy = np.array([197, 218, 256, 328, 413,525, 646, 646, 777, 1159, 1838, 2417, 3240, 4257, 4955, 4955, 5752, 6620, 7738, 8966, 10402], dtype=float)# get the deltas to check if there was no increase# between two consecutive data points dy = np.diff(y)# these are the places without increaseidx = np.argwhere(dy) #could also be np.where(dy == 0.0)[0]y_fixed = y.copy()# create the x axis, probably days x = np.arange(y.shape[0])# Hack: increase the second identical value be a# small amount so the interpolation works# increase the indices by one to increment the second valuey_fixed[idx + 1] += 0.001# you need scipy > 0.17 for extrapolation to workf = interp1d(y_fixed, x, fill_value="extrapolate")# there are the values you need?y_half = y / 2.0# get the according x values by interpolationx_interp = f(y_half)# delta between the current day and the date when# the value was halfdbl = x - x_interp# this already looks quite good, but double check!print(dbl)也许 x 轴需要移动。或者也许它毕竟是正确的。我明天会用新鲜的大脑来思考这个问题。下图显示了两种算法,其中包含计算出的指数数据,其中两个位置设置为非递增值。
-
不负相思意
可能最终会看起来像这样。ACCURACY = 0cases = [197, 218, 256, 328, 413,525, 646, 646, 777, 1159, 1838, 2417, 3240, 4257, 4955, 4955, 5752, 6620, 7738, 8966, 10402]doubling = []for t in range(len(cases)): found = False for t_2 in range(t): if cases[t_2] - (cases[t] // 2) > ACCURACY: doubling.append(t - t_2) found = True break # Append nothing if value not found if not found: doubling.append(None)
-
拉丁的传说
我正在处理这些数据。这是一个老派的解决方案。我跟踪了您的解决方案,但无法完全遵循它。但是我的不是那么优雅,但我认为这是正确的...而且图表看起来与您的图表非常相似...!import numpy as npreadings = np.array([197, 218, 256, 328, 413,525, 646, 646, 777, 1159, 1838, 2417, 3240, 4257, 4955, 4955, 5752, 6620, 7738, 8966, 10402], dtype=float) readingsLength = len(readings)double = np.zeros(readingsLength)for i in range( readingsLength - 1, -1, -1): target = readings[i] count = 0 for j in range(i, -1, -1): diffsofar = target-readings[j] exact = target / 2 if diffsofar > exact: f = (exact - readings[j]) / (readings[j]-readings[j+1]) + count double[i] = f break else: count = count+1print(double)