提交 dfc3ab06 编写于 作者: Z zhupengyang 提交者: hong19860320

fix argmax doc (#1261)

* fix argmax doc
test=document_preview

* fix
test=document_preview
上级 b99c4b8f
......@@ -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]]
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册