Skip to main content
 首页 » 编程设计

python之tensorflow:如何喂养 numpy.ndarray

2025年04月02日34jpfss

我解码了一张 JPEG 图像,并将它的形状设置为 n_samples x n_features 作为二维 numpy.ndarray。我按如下方式将其提供给 tensorflow:

sess.run(train_step, feed_dict={X : train_set.Features, y_ : train_set.labels})  

这会返回一个 TypeError:TypeError: unhashable type: 'numpy.ndarray'。

我认为这是一个简单的问题,但我找不到好的建议。我发现最接近的是这篇关于堆栈溢出的帖子,但据我所知,这就是我所做的。

请您参考如下方法:

我猜你的 X 和 train_set.Features 可能有不同的形状。 例如,

# cifar10 datasets  
x = tf.placeholder(tf.float32,shape = (None,32,32,3)) 
y = tf.placeholder(tf.float32,shape = (None,10)) 
print x_batch.shape   # (batch_size,32,32,3) 
print y_batch.shape   # (batch_size,10) 
# and feed_dict should be 
feed_dict = {x:x_batch,y:y_batch}