我想切片张量以通过索引列表获得特定张量,例如:
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
答案 0 :(得分:1)
首先,首先评估张量。然后,您可以将它们编入索引:
var sys = require('util')
var exec = require('child_process').exec;
function puts(error, stdout, stderr) {
console.log(stdout)
}
// this is where you should get your path/filename
var filename = "login";
// execute unix command 'file'
exec("file " + filename, puts);
输出:
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]]))