编程语言
首页 > 编程语言> > python-相邻数据比值

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,list,neigh,range,相邻,rate,data,round
来源: https://www.cnblogs.com/wxyz94/p/15584073.html