tensorflow中stack和unstack的使用
import tensorflow as tf
a = tf.constant([1,2,3])
b = tf.constant([4,5,6])
c = tf.stack([a,b],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))

计算结果:

"C:\Program Files\Anaconda3\python.exe" D:/pycharmprogram/tensorflow_learn/rnn_learn/tf_unstack_learn.py
(3, 2)
2018-05-15 17:44:02.277600: W C:\tf_jenkins\home\workspace\rel-win\M\windows\PY\35\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.
2018-05-15 17:44:02.277600: W C:\tf_jenkins\home\workspace\rel-win\M\windows\PY\35\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX2 instructions, but these are available on your machine and could speed up CPU computations.
[[1 4]
 [2 5]
 [3 6]]
[array([1, 4]), array([2, 5]), array([3, 6])]
[array([1, 2, 3]), array([4, 5, 6])]

Process finished with exit code 0

阅读更多
个人分类: tensorflow
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

不良信息举报

tensorflow中stack和unstack的使用

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭