Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
FluidDoc
提交
c90ad271
F
FluidDoc
项目概览
PaddlePaddle
/
FluidDoc
通知
10
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
23
列表
看板
标记
里程碑
合并请求
111
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
F
FluidDoc
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
23
Issue
23
列表
看板
标记
里程碑
合并请求
111
合并请求
111
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
c90ad271
编写于
9月 27, 2019
作者:
Z
zhupengyang
提交者:
hong19860320
9月 27, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix tensor_array_to_tensor doc (#1413)
* fix tensor_array_to_tensor doc test=document_preview * fix test=document_preview
上级
51e1e5cc
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
24 addition
and
35 deletion
+24
-35
doc/fluid/api_cn/layers_cn/tensor_array_to_tensor_cn.rst
doc/fluid/api_cn/layers_cn/tensor_array_to_tensor_cn.rst
+24
-35
未找到文件。
doc/fluid/api_cn/layers_cn/tensor_array_to_tensor_cn.rst
浏览文件 @
c90ad271
...
...
@@ -5,35 +5,14 @@ tensor_array_to_tensor
.. py:function:: paddle.fluid.layers.tensor_array_to_tensor(input, axis=1, name=None)
此函数在指定轴上连接LodTensorArray中的元素,并将其作为输出返回。
简单示例如下:
.. code-block:: text
Given:
input.data = {[[0.6, 0.1, 0.3],
[0.5, 0.3, 0.2]],
[[1.3],
[1.8]],
[[2.3, 2.1],
[2.5, 2.4]]}
axis = 1
Then:
output.data = [[0.6, 0.1, 0.3, 1.3, 2.3, 2.1],
[0.5, 0.3, 0.2, 1.8, 2.5, 2.4]]
output_index.data = [3, 1, 2]
该OP在指定轴上连接LoDTensorArray中的元素。
参数:
- **input** (
list) - 输入的LodTensorArray
- **axis** (int
) - 整数轴,tensor将会和它连接在一起
- **name** (str
|None) - 该layer的名字,可选。如果设置为none,layer将会被自动命名
- **input** (
Variable) - 输入的LoDTensorArray。支持的数据类型为:float32、float64、int32、int64。
- **axis** (int
,可选) - 指定对输入Tensor进行运算的轴, ``axis`` 的有效范围是[-R, R),R是输入 ``input`` 中Tensor的Rank,``axis`` 为负时与 ``axis`` +R 等价。默认值为1。
- **name** (str
,可选) – 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。
返回:
Variable: 连接的输出变量,输入LodTensorArray沿指定axis连接。
返回:LoDTensor
返回类型: Variable
...
...
@@ -41,17 +20,27 @@ tensor_array_to_tensor
.. code-block:: python
import paddle.fluid as fluid
tensor_array = fluid.layers.create_parameter(shape=[784, 200], dtype='float32')
output, output_index = fluid.layers.tensor_array_to_tensor(input=tensor_array)
import paddle.fluid as fluid
import numpy as np
place = fluid.CPUPlace()
x1 = fluid.layers.data(name="x", shape=[2,2], lod_level=0)
tmp = fluid.layers.fill_constant(shape=[2,3], dtype="float32", value=1)
x_arr = fluid.layers.create_array(dtype="float32")
c0 = fluid.layers.fill_constant(shape=[1], dtype='int64', value=0)
fluid.layers.array_write(x=tmp, i=c0, array=x_arr)
c1 = fluid.layers.fill_constant(shape=[1], dtype='int64', value=1)
fluid.layers.array_write(x=x1, i=c1, array=x_arr)
output, output_index = fluid.layers.tensor_array_to_tensor(input=x_arr, axis=1)
exe = fluid.Executor(place)
exe.run(fluid.default_startup_program())
feedx = fluid.LoDTensor()
feedx.set(np.array([[1.3,-2.4],[0,4]]).astype("float32"), place)
res = exe.run(fluid.default_main_program(), feed={'x':feedx}, fetch_list=[output], return_numpy=False)
print(np.array(res[0]))
# [[ 1. 1. 1. 1.3 -2.4]
# [ 1. 1. 1. 0. 4. ]]
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录