从所有中减去last
,然后将所有除以first
。
emil ~ > python
Python 2.7.1 (r271:86832, Aug 5 2011, 03:30:24)
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> l = [0.31622776601683794, 0.26591479484724945, 0.24028114141347545, 0.22360679774997896,
... 0.21147425268811282, 0.20205155046766235, 0.19441308418139638, 0.1880301546543197,
... 0.18257418583505536, 0.17782794100389226]
>>> l
[0.31622776601683794, 0.26591479484724945, 0.24028114141347545, 0.22360679774997896, 0.21147425268811282, 0.20205155046766235, 0.19441308418139638, 0.1880301546543197, 0.18257418583505536, 0.17782794100389226]
>>> len(l)
10
>>> l1 = []
>>> l1[:] = [x - l[9] for x in l]
>>> l1
[0.13839982501294568, 0.08808685384335718, 0.06245320040958319, 0.0457788567460867, 0.03364631168422055, 0.024223609463770085, 0.01658514317750412, 0.010202213650427422, 0.004746244831163093, 0.0]
>>> l2 = []
>>> l2[:] = [x/l1[0] for x in l1]
>>> l2
[1.0, 0.6364665116817719, 0.4512520185899182, 0.33077250453029566, 0.2431094958470745, 0.175026301236322, 0.11983500106270202, 0.0737155097520761, 0.03429371988526097, 0.0]
并归一化(sum = 1) :
>>> l3 = []
>>> l3[:] = [x/sum(l2) for x in l2]
>>> l3
[0.3263205883093977, 0.20769212653122596, 0.14725282418206537, 0.107937878274899, 0.07933163370841843, 0.05711468558905446, 0.03910462804683822, 0.024054888509824617, 0.01119074684827605, 0.0]
但是,除非第一个和最后一个之间的数字之和为 0 ,否则您无法满足您要求的条件,因此对于您的示例数据,这是不可能的。