codecamp

TensorFlow函数:tf.stack

tf.stack函数

tf.stack(
    values,
    axis=0,
    name='stack'
)

定义在:tensorflow/python/ops/array_ops.py.

请参阅指南:图层(contrib)>构建神经网络图层的更高级别操作,张量变换>分割和连接

将秩为 R 的张量列表堆叠成一个秩为 (R+1) 的张量.

将 values 中的张量列表打包成一个张量,该张量比 values 中的每个张量都高一个秩,通过沿 axis 维度打包.给定一个形状为(A, B, C)的张量的长度 N 的列表;

如果 axis == 0,那么 output 张量将具有形状(N, A, B, C).如果 axis == 1,那么 output 张量将具有形状(A, N, B, C).

例如:

x = tf.constant([1, 4])
y = tf.constant([2, 5])
z = tf.constant([3, 6])
tf.stack([x, y, z])  # [[1, 4], [2, 5], [3, 6]] (Pack along first dim.)
tf.stack([x, y, z], axis=1)  # [[1, 2, 3], [4, 5, 6]]

这与 unpack 相反,numpy 相当于:

tf.stack([x, y, z]) = np.stack([x, y, z])

函数参数:

  • values:具有相同形状和类型的 Tensor 对象列表.
  • axis:一个 int,要一起堆叠的轴,默认为第一维,负值环绕,所以有效范围是[-(R+1), R+1).
  • name:此操作的名称(可选).

函数返回值:

  • output:与 values 具有相同的类型的堆叠的 Tensor.

可能引发的异常:

  • ValueError:如果 axis 超出范围 [ - (R + 1),R + 1),则引发此异常.
TensorFlow函数:tf.squeeze
TensorFlow函数:tf.stop_gradient
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

TensorFlow 函数介绍

TensorFlow 函数模块:tf

TensorFlow的image模块

TensorFlow使用之tf.io

TensorFlow使用之tf.keras

TensorFlow函数教程:tf.keras.applications

TensorFlow函数教程:tf.keras.backend

TensorFlow使用之tf.metrics

TensorFlow使用之tf.nn

TensorFlow使用之tf.python_io

TensorFlow 功能函数

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }