0
我有一个矩阵:索引中TensorFlow
Params =
[[ 0 1 2 3]
[ 4 5 6 7]
[ 8 9 10 11]]
对于每一行我想用列索引选择一些元素:
col_indices =
[[0 1]
[1 2]
[2 3]]
在numpy的,我可以创建行索引:
row_indices =
[[0 0]
[1 1]
[2 2]]
,做params[row_indices, col_indices]
在TenforFlow,我这样做:
tf_params = tf.constant(params)
tf_col_indices = tf.constant(col_indices, dtype=tf.int32)
tf_row_indices = tf.constant(row_indices, dtype=tf.int32)
tf_params[row_indices, col_indices]
但引发的错误:
ValueError: Shape must be rank 1 but is rank 3
是什么意思?我应该如何正确地进行这种索引?
谢谢!
非常感谢您的回答!但我不明白“排名1”和“排名3”来自哪里。我使用的两个指数矩阵都有2个等级。我期望的结果也应该有2个等级,与numpy代码相同。有任何想法吗?谢谢! – xyd
为什么行和列索引矩阵的秩为2?他们代表什么?我想你正试图以一种错误的方式做点什么!提供完整的代码,以便我们可以运行和测试。 –
请看我上面的numpy代码,我想在tensorflow中实现精确的索引。谢谢 – xyd