tensorflow 中 tf.concat 和 tf.stack 使用

本文介绍了 TensorFlow 中的 `tf.concat` 和 `tf.stack` 函数,用于张量的连接操作。`tf.concat` 沿指定维度拼接多个张量,而 `tf.stack` 则在新的维度上堆叠张量,提供了不同方式的组合张量数据的方法。
摘要由CSDN通过智能技术生成

一、 tf.concat 

官方解释文档:https://tensorflow.google.cn/api_docs/python/tf/concat

函数原型:

tf.concat(
    values,                    # 要连接的张量
    axis,                      # 指定的连接维度
    name='concat'
)

官方解释:
values: A list of Tensor objects or a single Tensor.
axis: 0-D int32 Tensor. Dimension along which to concatenate. Must be in the range [-
       rank(values), rank(values)). As in Python, indexing for axis is 0-based. Positive         
       axis in the rage of [0, rank(values)) refers to axis-th dimension. And negative axis 
       refers to axis + rank(values)-th dimension.
name: A name for the operation (optional).

这是将张量按指定维度进行连接的函数。如下面实例所示:

t1 = [[1, 2, 3], [4, 5, 6]]
t2 = [[7, 8, 9], [10, 11, 12]]
tf.concat([t1, t2], 0)  # [[1, 2, 3]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值