python - 将列表数组转换为 Keras 输入

标签 python numpy tensorflow keras

给定一个以下形式的数组

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)

如何准备它以供 TensorFlow 2.0 RC0 中的 Keras 模型使用?在当前形式下,它会抛出错误

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

而且我似乎无法以我熟悉的形式得到它,

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

最佳答案

如果您发现自己处于这种情况,您可以使用以下方法更正您的数组:

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

关于python - 将列表数组转换为 Keras 输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57760510/

相关文章:

python - 抓取json结构中的所有嵌套键

python - 如何在 python 中访问 nametuples 中的元素?

python请求将字符串作为文件发送

python - 在 Python 中排除 collections.Counter 中的零

python - 如何使用 NumPy 将单色噪声添加到 PyGame 表面?

tensorflow - 如何使用Tensorflow在Keras中禁用GPU?

random - 使用 tf.random 多次运行 session 会返回不同的 conv2d 值

python - 如何以随机顺序打印列表中的单词,以便每个单词只打印一次(使用Python)

python - 在二维数组中查找重复数组并将数字添加到元组中

machine-learning - 将图像输入 tensorflow