print('\nCollecting experience')
for ep in range(400):
state = env.reset()
#print(state.shape)
#state = np.array(state)
state = state.transpose((2, 0, 1))
#state = torch.from_numpy(state)
state = Variable(torch.from_numpy(state))
state = state.unsqueeze(0)
print("AA", state.shape)
episode_reward = 0
step = 0
for i in range(50):
# env.render()
print("BB",state.shape)
action = agent.get_action(state)
我已经尝试过,它可以在没有循环的情况下工作,它也不适用于 while 循环
<小时/>打印内容:
Collecting experience
AA torch.Size([1, 1, 84, 84])
BB torch.Size([1, 1, 84, 84])
BB (84, 84, 1)
是什么导致了第二次 BB 打印?
最佳答案
解决了它,结果发现问题出现在循环中,下一个输入不一样,所以将处理放入numpy并将事物放入函数中,并且它起作用了
关于python - torch 张量在 for/while 循环中更改为 numpy 数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59504791/