python concat axis_tf.concat中axis的含义与使用详解

tensorflow中tf.concat的axis的使用我一直理解的比较模糊,这次做个笔记理下自己的思路。

import tensorflow as tf

tf.enable_eager_execution()

import numpy as np

先生成两个矩阵m1, 和m2, 大小为两行三列

m1 = np.random.rand(2,3) # m1.shape (2,3)

m1

>>array([[0.44529968, 0.42451167, 0.07463199],

[0.35787143, 0.22926186, 0.34583839]])

m2 = np.random.rand(2,3) # m2.shape (2,3)

m2

>>array([[0.92811531, 0.6180391 , 0.71969461],

[0.00564108, 0.55381637, 0.17155987]])

接下来采用tf.concat进行连接,简单来说,axis=0实际就是按行拼接,axis=1就是按列拼接

# axis = 0

m3 = tf.concat([m1,m2],axis=0)

m3

>> array([[0.44529968, 0.42451167, 0.07463199],

[0.35787143, 0.22926186, 0.34583839],

[0.92811531, 0.6180391 , 0.71969461],

[0.00564108, 0.55381637, 0.17155987]])

m3.shape

>> (4,3

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值