python-相邻数据比值

## 相邻两个数据求比值
def neigh_rate(data):
    neigh_rate = {}
#  neigh_rate = []  # 报错 list assignment index out of range
    for i in range(len(data)):
        for j in range(i+1, len(data)):
            neigh_rate[i] = data[j] / data[i]
    result = list(neigh_rate.values()) # 提取字典值并转化成list格式
    re_round = [round(x, 4)  for x in result] # 将转化率保留四位小数
    return re_round

python-相邻数据比值

上一篇:观察者模式(java)


下一篇:AEJoy —— 表达式之模拟计时时钟【JS】