Pad基本功能展开,展开,paddle,基础,函数,expandexpandas

发表时间:2020-10-15

expand 官方文档: https://www.paddlepaddle.org.cn/documentation/docs/zh/api_cn/layers_cn/expand_cn.html

paddle.fluid.layers. expand ( x , expand_times , name=None )

根据参数 expand_times 对输入 x 的各维度进行复制。通过参数 expand_times 来为 x 的每个维度设置复制次数。

expand_as官方文档: https://www.paddlepaddle.org.cn/documentation/docs/zh/api_cn/layers_cn/expand_as_cn.html

paddle.fluid.layers. expand_as ( x , target_tensor , name=None )

根据输入的variable target_tensor 对输入 x 的各维度进行广播。

expand 示例:

import paddle.fluid as fluid

# example 1:
data_1 = fluid.layers.fill_constant(shape=[2, 3, 1], dtype='int32', value=0)
expanded_1 = fluid.layers.expand(data_1, expand_times=[1, 2, 2])
# the shape of expanded_1 is [2, 6, 2].

print(expanded_1.shape)

结果:

[2, 6, 2]

expand_as 示例:

import paddle.fluid as fluid
import numpy as np

data = fluid.data(name="data", shape=[-1,10], dtype='float64')
target_tensor = fluid.data(name="target_tensor", shape=[-1,20], dtype='float64')
result = fluid.layers.expand_as(x=data, target_tensor=target_tensor)

use_cuda = False
place = fluid.CUDAPlace(0) if use_cuda else fluid.CPUPlace()
exe = fluid.Executor(place)
exe.run(fluid.default_startup_program())

x = np.random.rand(3,10)
y = np.random.rand(3,20)
output= exe.run(feed={"data":x,
                      "target_tensor":y},
                fetch_list=[result.name])
print(output)
#(3,20)

结果:

文章来源互联网,如有侵权,请联系管理员删除。邮箱:417803890@qq.com / QQ:417803890

微配音

Python Free

邮箱:417803890@qq.com
QQ:417803890

皖ICP备19001818号
© 2019 copyright www.pythonf.cn - All rights reserved

微信扫一扫关注公众号:

联系方式

Python Free