zoukankan      html  css  js  c++  java
  • tf.stack和tf.unstack

     1 import tensorflow as tf
     2 
     3 a = tf.constant([1,2,3])
     4 b = tf.constant([4,5,6])
     5 
     6 c1 = tf.stack([a,b],axis=0)
     7 c2 = tf.stack([a,b],axis=1)
     8 #take c2 for example showing results of unstack
     9 d1 = tf.unstack(c2,axis=0) # Return: The list of Tensor objects unstacked from value.
    10 d2 = tf.unstack(c2,axis=1)
    11 
    12 with tf.Session() as sess:
    13     print('c1(with shape:{}):
    {}'.format(c1.shape, sess.run(c1)))
    14     print('c2(with shape:{}):
    {}'.format(c2.shape, sess.run(c2)))
    15     
    16     print('d1(with length:{}):
    {}'.format(len(d1), sess.run(d1)))
    17     print('d2(with length:{}):
    {}'.format(len(d2), sess.run(d2)))

    运行结果:

    官方API:

    https://www.tensorflow.org/api_docs/python/tf/stack

    https://www.tensorflow.org/api_docs/python/tf/unstack

  • 相关阅读:
    elf和内存分布
    平衡二叉树
    sdio驱动
    wifi
    阻塞赋值与非阻塞赋值
    线性失真与非线性失真
    数字前端,后端介绍
    总线
    并行全比较排序算法&并对角标排序
    verilog memory
  • 原文地址:https://www.cnblogs.com/wxiaoli/p/8945683.html
Copyright © 2011-2022 走看看