unstack( value, num=None, axis=0, name=‘unstack‘ )
tf.unstack()
将给定的R维张量拆分成R-1维张量
将value根据axis分解成num个张量,返回的值是list类型,如果没有指定num则根据axis推断出!
DEMO:
import tensorflow as tf a = tf.constant([3,2,4,5,6]) b = tf.constant([1,6,7,8,0]) c = tf.stack([a,b],axis=0) d = tf.stack([a,b],axis=1) e = tf.unstack([a,b],axis=0) f = tf.unstack([a,b],axis=1) with tf.Session() as sess: print(sess.run(c)) print(sess.run(d)) print(sess.run(e)) print(sess.run(f))
输出:
[[3 2 4 5 6]
[1 6 7 8 0]]
--------------------
[[3 1]
[2 6]
[4 7]
[5 8]
[6 0]]
----------------------
[array([3, 2, 4, 5, 6]), array([1, 6, 7, 8, 0])]
----------------------
[array([3, 1]), array([2, 6]), array([4, 7]), array([5, 8]), array([6, 0])]
时间: 2024-10-12 11:39:03