我正在尝试用Python为游戏创建训练数据。为此,我选择创建一个二维列表。但列表没有正确更新

问题描述 投票:0回答:1

这是我写的代码的一部分:

for e in range(episodes):
    qm=random.randint(0,5)
    env.game(action)
    fps.tick(1)
    screen.fill(bgcolor)
    s=env.get_state()
    rew=s[12]
    q1=rew+g*qm
    for k in range(12):
        tlistc[k]=s[k]
    tlistc[12]=action
    tlistc[13]=q1
    tlistm.append('a')
    tlistm[e]=tlistc
    if s[13]==1:
        env.game_reset()        
    action=random.randint(0,3)
    print(tlistm)

This is what being returned to me

但是每次迭代之后,tlistm 的所有项目都会更新到 tlistc,而不是仅最后一个项目。

我犯了一些错误还是我遗漏了什么?

我检查并重新检查了我的代码,但似乎无法理解问题..

python list artificial-intelligence dqn
1个回答
0
投票

tlistc 在 for 循环之外创建。每次迭代,您都会改变同一个对象。

您应该在 for 循环内创建一个新的 tlistc。

© www.soinside.com 2019 - 2024. All rights reserved.