实现一个式子,我太cai了,没弄明白

x是一个列表,比如x = [1,2,3]
T = 2
我要得到一个新的列表y,新列表中的数取值规则如下,需要T个x中的数计算得到

img


WechatIMG981.jpeg

解释在代码中,有用请点采纳~

def y(x):
    result = 0  # 结果
    start = 0 if x < T else x - T + 1  # 开始的下标
    end = 1 if x + 1 < T else x + 1  # 结束的下标
    for index, item in enumerate(range(start, end)):  # index为算式序号,item为乘的列表下标
        result += (index + 1) * X[item]
    return result


Y = []
T = 2
X = [1, 2, 3, 4, 5, 6]
for i in range(len(X)):
    Y.append(y(i))
print(Y)
T=#这俩自己填
t=int(T)
x=[]#
y=[]
tick=0
while True:
  if tick==len(x):
    break
  else:
    y.append(0)
    while True:
      if t==0:
        break
      else:
        y[tick]=x[tick-t]*t+y[tick]
        t=t-1
    tick=tick+1
    t=int(T)