如果直接使用print函数得到的是张量的shape和dtype。
primes = tf.constant([2,3,5,7,11,13], dtype = tf.int32) print("primes:", primes)
得到的结果是:
primes: Tensor("Const:0", shape=(6,), dtype=int32)
如果只想看到张量的具体值,可以采用如下方法:
primes = tf.constant([2,3,5,7,11,13], dtype = tf.int32) ones = tf.constant(-1, dtype = tf.int32) primes_sub_ones = tf.add(primes, ones) print("primes:", primes_sub_ones) with tf.Session() as sess: print(sess.run(primes_sub_ones))
得到的结果如下:
[ 1 2 4 6 10 12]