Cherie_233 2021-03-22 21:00 采纳率: 0%
浏览 744

强化学习训练中报错setting an array element with a sequence

在强化学习训练中出现错误,请问如何解决?

e:\DQN_3D\Env3D.py:38: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray
  self.window = np.array([self.x0,self.y0,self.f0,self.rad0]).reshape(1,4)
e:\DQN_3D\Env3D.py:134: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 
'dtype=object' when creating the ndarray

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "e:/DQN_3D/TrainLibrary3D.py", line 126, in <module>
    train(rssRow)
  File "e:/DQN_3D/TrainLibrary3D.py", line 39, in train
    RL.learn()
  File "e:\DQN_3D\DeepQ.py", line 187, in learn
    self.learning_rate_step:self.learn_step_counter,
  File "D:\anaconda\Anaconda\envs\TF2.1\lib\site-packages\tensorflow\python\client\session.py", line 958, in run
    run_metadata_ptr)
  File "D:\anaconda\Anaconda\envs\TF2.1\lib\site-packages\tensorflow\python\client\session.py", line 1150, in _run
    np_val = np.asarray(subfeed_val, dtype=subfeed_dtype)
  File "D:\anaconda\Anaconda\envs\TF2.1\lib\site-packages\numpy\core\_asarray.py", line 83, in asarray
    return array(a, dtype, copy=False, order=order)
ValueError: setting an array element with a sequence.

主要是函数learn这一块的问题:

self.sess.run(
            [self._train_op, self.loss],
            feed_dict={    
                self.s: batch_memory[:, :self.n_features],
                self.a: batch_memory[:, self.n_features],
                self.r: batch_memory[:, self.n_features + 1],
                self.s_: batch_memory[:, -self.n_features:],
                self.learning_rate_step:self.learn_step_counter,
            })
  • 写回答

1条回答 默认 最新

  • 爱笑的男孩。 2023-06-27 10:29
    关注

    这个错误通常出现在使用numpy数组时,尝试将一个序列赋值给数组的单个元素,但数组的元素只能是标量。请检查你的代码,确保在向numpy数组中赋值时,将标量(单个值)赋值给单个元素。

    另外,请注意,如果你在尝试将序列赋值给数组的单个元素时出现此错误,它可能意味着序列的维数与数组的维数不匹配。在这种情况下,请确保将序列的维度与数组的维度匹配。

    评论

报告相同问题?

悬赏问题

  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler