paddle 基础函数 argmax

文档链接: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)] 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值