Given indices
有形状[batch_size, sequence_len]
, updates
有形状[batch_size, sequence_len, sampled_size]
, to_shape
有形状[batch_size, sequence_len, vocab_size]
, where vocab_size
>>sampled_size
,我想用tf.scatter
来映射updates
到一个巨大的张量to_shape
,使得to_shape[bs, indices[bs, sz]] = updates[bs, sz]
。也就是说,我想绘制地图updates
to to_shape
一行一行。请注意sequence_len
and sampled_size
是标量张量,而其他则是固定的。我尝试执行以下操作:
new_tensor = tf.scatter_nd(tf.expand_dims(indices, axis=2), updates, to_shape)
但我收到一个错误:
ValueError: The inner 2 dimension of output.shape=[?,?,?] must match the inner 1 dimension of updates.shape=[80,50,?]: Shapes must be equal rank, but are 2 and 1 for .... with input shapes: [80, 50, 1], [80, 50,?], [3]
你能告诉我如何使用吗scatter_nd
适当地?提前致谢!