np.argmax()使用说明

np.argmax()是numpy中获取array的某一个维度中数值最大的那个元素的索引,实例如下:

import numpy as np

x = np.random.normal(1,4,(3,5))
y = np.argmax(x,axis=1)
print(x)
print(x.shape)
print(y)
print(y.shape)

输出结果为:
[[ 0.21732346 -3.48525172 -2.19230097  1.53942774  1.51051946]
 [-4.298163    1.24736953 -1.24371032 -1.0929181  -2.04791179]
 [ 2.29861605  2.14217121 -2.61879844  5.49840773  2.11360768]]
(3, 5)
[3 1 3]
(3,)

其中x=np.random.normal(1,4,(3,5)),代表生成的x是平均值为1,均方差4,尺寸为[3,5]的array。

y = np.argmax(x,axis=1),中的axis=1指定代表我要查找的最大元素在第1维中的索引值。

另一个实例如下:

import numpy as np

x = np.random.normal(1,4,(3,5))
y = np.argmax(x,axis=0)
print(x)
print(x.shape)
print(y)
print(y.shape)

输出结果为:
[[ 2.9624991   7.85484938  1.45422659  5.76279443 -4.96967595]
 [ 5.23517858  4.15894847  8.83419527  4.76619198  9.31344739]
 [-1.73967324  3.03142305 -3.28402655  4.01823193  2.01979302]]
(3, 5)
[1 0 1 0 1]
(5,)

axis=0,代表我要查找的最大元素在第0维中的索引值。

 

  • 18
    点赞
  • 65
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值