沿一维连接张量。
用法
tf.concat(
values, axis, name='concat'
)参数
-
valuesTensor对象的列表或单个Tensor。 -
axis0-Dint32Tensor。要连接的维度。必须在[-rank(values), rank(values))范围内。与 Python 中一样,轴的索引是从 0 开始的。[0, rank(values))范围内的正轴指的是axis-th 维度。负轴是指axis + rank(values)-th 维度。 -
name操作的名称(可选)。
返回
-
由输入张量串联产生的
Tensor。
沿维度 axis 连接张量列表 values 。如果 values[i].shape = [D0, D1, ... Daxis(i), ...Dn] ,则连接结果具有形状
[D0, D1, ... Raxis, ...Dn]
其中
Raxis = sum(Daxis(i))
也就是说,来自输入张量的数据沿 axis 维度连接。
输入张量的维数必须匹配,除axis之外的所有维数必须相等。
例如:
t1 = [[1, 2, 3], [4, 5, 6]]
t2 = [[7, 8, 9], [10, 11, 12]]
tf.concat([t1, t2], 0)
<tf.Tensor:shape=(4, 3), dtype=int32, numpy=
array([[ 1, 2, 3],
[ 4, 5, 6],
[ 7, 8, 9],
[10, 11, 12]], dtype=int32)>
tf.concat([t1, t2], 1)
<tf.Tensor:shape=(2, 6), dtype=int32, numpy=
array([[ 1, 2, 3, 7, 8, 9],
[ 4, 5, 6, 10, 11, 12]], dtype=int32)>
在 Python 中,axis 也可以是负数。负数 axis 被解释为从排名末尾开始计数,即 axis + rank(values) -th 维度。
例如:
t1 = [[[1, 2], [2, 3]], [[4, 4], [5, 3]]]
t2 = [[[7, 4], [8, 4]], [[2, 10], [15, 11]]]
tf.concat([t1, t2], -1)
<tf.Tensor:shape=(2, 2, 4), dtype=int32, numpy=
array([[[ 1, 2, 7, 4],
[ 2, 3, 8, 4]],
[[ 4, 4, 2, 10],
[ 5, 3, 15, 11]]], dtype=int32)>
注意:如果您沿新轴连接,请考虑使用堆栈。例如:
tf.concat([tf.expand_dims(t, axis) for t in tensors], axis)
可以改写为
tf.stack(tensors, axis=axis)
相关用法
- Python tf.config.list_logical_devices用法及代码示例
- Python tf.config.experimental.get_memory_usage用法及代码示例
- Python tf.config.list_physical_devices用法及代码示例
- Python tf.config.get_logical_device_configuration用法及代码示例
- Python tf.config.experimental.get_memory_info用法及代码示例
- Python tf.config.run_functions_eagerly用法及代码示例
- Python tf.config.experimental.enable_tensor_float_32_execution用法及代码示例
- Python tf.convert_to_tensor用法及代码示例
- Python tf.config.experimental_connect_to_cluster用法及代码示例
- Python tf.config.experimental.set_memory_growth用法及代码示例
- Python tf.config.experimental_connect_to_host用法及代码示例
- Python tf.config.set_visible_devices用法及代码示例
- Python tf.config.set_logical_device_configuration用法及代码示例
- Python tf.config.experimental.enable_op_determinism用法及代码示例
- Python tf.constant_initializer.from_config用法及代码示例
- Python tf.config.get_visible_devices用法及代码示例
- Python tf.config.experimental.get_device_details用法及代码示例
- Python tf.config.experimental.ClusterDeviceFilters用法及代码示例
- Python tf.constant用法及代码示例
- Python tf.config.experimental.reset_memory_stats用法及代码示例
注:本文由纯净天空筛选整理自tensorflow.org大神的英文原创作品 tf.concat。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
