【发布时间】:2016-08-27 14:41:29
【问题描述】:
例如,在 Numpy 中,我可以得到一些这样的值。
d = np.array([[0, 1, 2], [3, 4, 5], [6, 7, 8]])
# array([[0, 1, 2],
# [3, 4, 5],
# [6, 7, 8]])
d[[0, 1, 2], [2, 1, 0]]
# array([2, 4, 6])
所以我可以检索 [2, 4, 6]。
如何在 TensorFlow 中做同样的事情?
x = tf.Variable([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
init_op = tf.initialize_all_variables()
with tf.Session() as sess:
sess.run(init_op)
print sess.run([x[[0, 1, 2], [2,1,0]]])[0]
它引发类型错误
TypeError: Bad slice index [0, 1, 2] of type <type 'list'>
我的问题是如何通过 TensorFlow 获得相同的值?
print sess.run([x[[0, 1, 2], [2,1,0]]])[0]
【问题讨论】:
标签: python numpy neural-network tensorflow