paddle 基础函数 concat

文档地址:https://www.paddlepaddle.org.cn/documentation/docs/zh/api_cn/layers_cn/concat_cn.html#concat

 

示例:

import paddle.fluid as fluid
import numpy as np

x1 = fluid.data(name="x1_", shape=[2, 3], dtype="float32")
x2 = fluid.data(name="x2_", shape=[2, 3], dtype="float32")
x3 = fluid.data(name="x3_", shape=[2, 2], dtype="float32")

out = fluid.layers.concat(input=[x1, x2, x3], axis=1) # axis=-1


place = fluid.CPUPlace()
exe = fluid.Executor(place)
exe.run(fluid.default_startup_program())

in1 = np.array([[1,2,3],
                [4,5,6]]).astype("float32")

in2 = np.array([[11,12,13],
                [14,15,16]]).astype("float32")

in3 = np.array([[21,22],
                [23,24]]).astype("float32")

output = exe.run(feed={"x1_": in1, "x2_": in2, "x3_": in3}, fetch_list = [out])
print(output)

官方文档 https://www.paddlepaddle.org.cn/documentation/docs/zh/api_cn/layers_cn/data_cn.html#data 中不推荐使用 paddle.fluid.layers.data ,因其在之后的版本中会被删除。请使用 paddle.fluid.data 。

 

结果:

[array([[ 1,  2,  3, 11, 12, 13, 21, 22],
       [ 4,  5,  6, 14, 15, 16, 23, 24]], dtype=int64)]

如果axis=0,就会报错,因为维度不一致。

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值