A
是一个tensorflow.tensor
形状(2261,)
我想从以下指数得到一个新的张量A
:[10,20,30]
我尝试了以下所有方法,但均无济于事:
A[[10,20,30]]
# *** ValueError: Index out of range using input dim 1; input has only 1 dims for 'strided_slice' (op: 'StridedSlice') with input shapes: [2261], [3], [3], [3].
A[10,20,30]
# same error as above
A[numpy.array([10,20,30])]
# *** ValueError: Shape must be rank 1 but is rank 2 for 'strided_slice' (op: 'StridedSlice') with input shapes: [2261], [1,3], [1,3], [1].
A[10]
# <tf.Tensor 'strided_slice:0' shape=() dtype=float32> - not an error but a shapeless tensor
A[tensorflow.constant(10)]
# same problem as above
为什么这些都不起作用,我该怎么办?
C = tf.nn.embedding_lookup(A, B)
其中B是张量,其值为[10,20,30]
供参考:https : //www.tensorflow.org/api_docs/python/nn/embeddings
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句