TensorFlow学习6:tf.stack和tf.unstack

tf.stack和tf.unstack分别表示矩阵的合并和分解

示例:

import tensorflow as tf
import sys
import os
import numpy as np

a = tf.constant([1 , 2 , 3])
b = tf.constant([4 , 5 , 6])

c = tf.stack([a , b] , axis=0)
d = tf.unstack(c , axis=0)
e = tf.unstack(c , axis=1)

with tf.Session() as sess:
    sess.run(tf.global_variables_initializer())
    print(sess.run(c))
    print(sess.run(d))
    print(sess.run(e))

[[1 2 3] 
[4 5 6]] 
[array([1, 2, 3]), array([4, 5, 6])] 
[array([1, 4]), array([2, 5]), array([3, 6])]

猜你喜欢

转载自blog.csdn.net/Softdiamonds/article/details/80511424
今日推荐