[英]TensorFlow Recommenders - ValueError: Shape must be rank 2 but is rank 3
[英]TensorFlow - Slicing tensor results in: ValueError: Shape (16491,) must have rank 3
我想對張量進行切片以按索引列表獲取特定張量,例如:
word_weight = tf.get_variable("word_weight", [20])
a= word_weight[ [1,6,5] ]
(我想得到word_weight[1], word_weight[6], word_weight[5]
)
但是當我運行代碼時出現以下錯誤:
ValueError: Shape (16491,) must have rank 3
首先,首先評估張量。 然后,您可以索引它們:
import tensorflow as tf
word_weight = tf.get_variable("word_weight", [20])
with tf.Session() as sess:
tf.initialize_all_variables().run()
x = sess.run(word_weight)
print(x[[1,6,5]])
# Or evaluete like this
print(sess.run([word_weight[1],word_weight[6],word_weight[5]]))
這輸出:
[ 1.61491954 0.66727936 -0.73491937]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.