From dfc3ab068c4fbeb66d0307c1c2c77d530af4405d Mon Sep 17 00:00:00 2001 From: zhupengyang <1165938320@qq.com> Date: Wed, 25 Sep 2019 17:29:36 +0800 Subject: [PATCH] fix argmax doc (#1261) * fix argmax doc test=document_preview * fix test=document_preview --- doc/fluid/api_cn/layers_cn/argmax_cn.rst | 53 +++++++++++++++--------- 1 file changed, 34 insertions(+), 19 deletions(-) diff --git a/doc/fluid/api_cn/layers_cn/argmax_cn.rst b/doc/fluid/api_cn/layers_cn/argmax_cn.rst index 74132b83e..47b6a49de 100644 --- a/doc/fluid/api_cn/layers_cn/argmax_cn.rst +++ b/doc/fluid/api_cn/layers_cn/argmax_cn.rst @@ -3,34 +3,49 @@ argmax ------------------------------- -.. py:function:: paddle.fluid.layers.argmax(x,axis=0) +.. py:function:: paddle.fluid.layers.argmax(x, axis=0) **argmax** -该功能计算输入张量元素中最大元素的索引,张量的元素在提供的轴上。 +该OP沿 ``axis`` 计算输入 ``x`` 的最大元素的索引。 参数: - - **x** (Variable)-用于计算最大元素索引的输入 - - **axis** (int)-用于计算索引的轴 + - **x** (Variable) - 输入的多维 ``Tensor`` ,支持的数据类型:float32、float64、int8、int16、int32、int64。 + - **axis** (int,可选) - 指定对输入Tensor进行运算的轴, ``axis`` 的有效范围是[-R, R),R是输入 ``x`` 的Rank, ``axis`` 为负时与 ``axis`` +R 等价。默认值为0。 -返回:存储在输出中的张量 +返回: ``Tensor`` ,数据类型int64 -返回类型:变量(Variable) +返回类型:Variable **代码示例**: .. code-block:: python - - import paddle.fluid as fluid - x = fluid.layers.data(name="x", shape=[3, 4], dtype="float32") - out = fluid.layers.argmax(x, axis=0) - out = fluid.layers.argmax(x, axis=-1) - - - - - - - - + import paddle.fluid as fluid + import numpy as np + + in1 = np.array([[[5,8,9,5], + [0,0,1,7], + [6,9,2,4]], + [[5,2,4,2], + [4,7,7,9], + [1,7,0,6]]]) + with fluid.dygraph.guard(): + x = fluid.dygraph.to_variable(in1) + out1 = fluid.layers.argmax(x=x, axis=-1) + out2 = fluid.layers.argmax(x=x, axis=0) + out3 = fluid.layers.argmax(x=x, axis=1) + out4 = fluid.layers.argmax(x=x, axis=2) + print(out1.numpy()) + # [[2 3 1] + # [0 3 1]] + print(out2.numpy()) + # [[0 0 0 0] + # [1 1 1 1] + # [0 0 0 1]] + print(out3.numpy()) + # [[2 2 0 1] + # [0 1 1 1]] + print(out4.numpy()) + # [[2 3 1] + # [0 3 1]] -- GitLab