for i in range(5): if r2_index[i] != ((len(data_history_conversion)) - 1): predict_day = dataset_history[96 * (r2_index[i] + 1):96 * (r2_index[i] + 2)] else: predict_day = dataset_history[96 * (r2_index[i - 1] + 1):96 * (r2_index[i - 1] + 2)] predict_sum.append(predict_day) 代码优化
时间: 2024-01-21 18:02:07 浏览: 93
sample-rate-conversion.zip_5VW_conversion_sample rate
可以将代码优化成如下形式:
```
for i in range(5):
if r2_index[i] != len(data_history_conversion) - 1:
predict_day = dataset_history[96 * (r2_index[i] + 1):96 * (r2_index[i] + 2)]
else:
predict_day = dataset_history[96 * (r2_index[i - 1] + 1):96 * (r2_index[i - 1] + 2)]
predict_sum.append(predict_day)
```
主要是将if语句的条件判断部分中的括号去掉,这样更加简洁清晰。
阅读全文