文档链接:https://www.paddlepaddle.org.cn/documentation/docs/zh/api_cn/layers_cn/argmax_cn.html
示例:
import paddle.fluid as fluid
import numpy as np
x1 = fluid.layers.data(name="x1_", shape=[2, 3, 4], dtype="float32")
print(x1.shape, "\n")
out = fluid.layers.argmax(x=x1, axis=0)
#out = fluid.layers.argmax(x=x1, axis=1)
#out = fluid.layers.argmax(x=x1, axis=2) # axis=-1
place = fluid.CPUPlace()
exe = fluid.Executor(place)
exe.run(fluid.default_startup_program())
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]]])
output = exe.run(feed={"x1_": in1}, fetch_list = [out])
print(output, "\n")
print(output[0].shape)
官方文档 https://www.paddlepaddle.org.cn/documentation/docs/zh/api_cn/layers_cn/data_cn.html#data 中不推荐使用 paddle.fluid.layers.data
,因其在之后的版本中会被删除。请使用 paddle.fluid.data
。
结果:
# axis=0
[array([[0, 0, 0, 0],
[1, 1, 1, 1],
[0, 0, 0, 1]], dtype=int64)]
# axis=1
[array([[2, 2, 0, 1],
[0, 1, 1, 1]], dtype=int64)]
# axis=2
[array([[2, 3, 1],
[0, 3, 1]], dtype=int64)]