Converting Array of Lists to Keras Input

谁说胖子不能爱 提交于 2021-02-08 01:49:30

问题


Given an array of the form

array([list([21603, 125, 737, 579, 2065, 10399, 1175, 0, 0, 0]),
       ...
       list([1896, 3917, 498, 296, 1452, 523, 754, 450, 3795, 341])],
      dtype=object)

How do you prepare it to be consumed by a Keras model in TensorFlow 2.0 RC0? In its current form it throws the error

ValueError: Failed to convert a NumPy array to a Tensor (Unsupported object type list).

and I can't seem to get it in the form I'm familiar with,

array([[21603, 125, 737, 579, 2065, 10399, 1175, 0, 0, 0],
       ...
       [1896, 3917, 498, 296, 1452, 523, 754, 450, 3795, 341]])

回答1:


If you find yourself in this situation, you can correct your array(s) with the following:

new_array = np.array(list(x for x in old_array))


来源:https://stackoverflow.com/questions/57760510/converting-array-of-lists-to-keras-input

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!