%%python2
import sys
import tensorflow as tf
print(sys.version)
a = tf.constant([1,2,3])
b = tf.constant([4,5,6])
f = tf.constant([4,5,6])
c = tf.stack([a,f],axis=1)
d = tf.unstack(c,axis=0)
e = tf.unstack(c,axis=1)
print(c.get_shape())
with tf.Session() as sess:
print(sess.run(c))
print(sess.run(d))
print(sess.run(e))
2.7.14 (default, Mar 22 2018, 15:04:47)
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)]
(3, 2)
[[1 4]
[2 5]
[3 6]]
[array([1, 4], dtype=int32), array([2, 5], dtype=int32), array([3, 6], dtype=int32)]
[array([1, 2, 3], dtype=int32), array([4, 5, 6], dtype=int32)]
总结:
tensorflow二维tensor中:
axis=0,指行
axis=1,指列tensorflow中 get_shape()函数,可以直接打印出tensor的shape,
- 注意的是:tensorflow中很多函数处理之后,变成list或者numpy.array