将列表数组转换为Keras输入 [英] Converting Array of Lists to Keras Input
本文介绍了将列表数组转换为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模型使用?在当前形式下,它会引发错误
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:无法将NumPy数组转换为张量(不支持的对象类型列表).
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]])
推荐答案
如果您遇到这种情况,可以使用以下方法更正阵列:
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))
这篇关于将列表数组转换为Keras输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文