【发布时间】:2018-04-06 12:22:53
【问题描述】:
我在 tensorflow 中创建了一个神经网络,并创建了这样的占位符:
input_tensor = tf.placeholder(tf.float32, shape = (None,n_input), name = "input_tensor")
output_tensor = tf.placeholder(tf.float32, shape = (None,n_classes), name = "output_tensor")
在训练过程中,我收到以下错误:
Traceback (most recent call last):
File "try.py", line 150, in <module>
sess.run(optimizer, feed_dict={X: x_train[i: i + 1], Y: y_train[i: i + 1]})
TypeError: unhashable type: 'numpy.ndarray'
我发现这是因为我的 x_train 和 y_train 的数据类型与占位符的数据类型不同。
我的 x_train 看起来有点像这样:
array([[array([[ 1., 0., 0.],
[ 0., 1., 0.]])],
[array([[ 0., 1., 0.],
[ 1., 0., 0.]])],
[array([[ 0., 0., 1.],
[ 0., 1., 0.]])]], dtype=object)
最初是这样的数据框:
0 [[1.0, 0.0, 0.0], [0.0, 1.0, 0.0]]
1 [[0.0, 1.0, 0.0], [1.0, 0.0, 0.0]]
2 [[0.0, 0.0, 1.0], [0.0, 1.0, 0.0]]
我做了x_train = train_x.values 来获取 numpy 数组
而 y_train 看起来是这样的:
array([[ 1., 0., 0.],
[ 0., 1., 0.],
[ 0., 0., 1.]])
x_train 有 dtype 对象,y_train 有 dtype float64。
我想知道的是如何更改我的训练数据的数据类型,以便它可以很好地与 tensorflow 占位符一起使用。或者如果我遗漏了什么,请提出建议。
【问题讨论】:
-
@BradSolomon 那只是因为我没有粘贴整个打印输出。我会编辑它。
-
@BradSolomon 它是单列,不用于索引。我之前误会了你。
标签: pandas numpy machine-learning tensorflow neural-network