tensorflow 2.0下张量的合并与分割

1、拼接张量:tf.concat()

用法:tf.concat([tensor1, tensor2, tensor3,…], axis, name=‘concat’)

tf.concat()拼接的张量只会改变一个维度上元素大小,其他维度的元素大小是保存不变,用axis的设置不同维度进行拼接。

In [1]: import tensorflow as tf

In [2]: a = tf.ones([4, 35, 8])
In [3]: b = tf.ones([2, 35, 8])

In [4]: c = tf.concat([a, b], axis=0)
In [5]: c.shape
Out [5]: TensorShape([6, 35, 8])

In [6]: import tensorflow as tf

In [7]: a = tf.ones([4, 32, 8])
In [8]: b = tf.ones([4, 3, 8])

In [9]: c = tf.concat([a, b], axis=0).shape
Out [9]: TensorShape([6, 35, 8])

注意:张量进行拼接时仅拼接的那个维度axis的元素大小可不同,其余维度上的元素大小必须相同才可进行拼接。

In [1]: import tensorflow as tf

In [2]: a = tf.ones([4, 35, 8])
In [3]: b = tf.ones([3, 33, 8])

In [4]: tf.concat([a, b], axis=0)
InvalidArgumentError: ConcatOp : Dimensions of inputs should match: shape[0] = [4,35,8] vs. shape[1] = [3,33,8] [Op
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值