Python基本函数:np.argmax(

Python基本函数:np.argmax()

格式:np.argmax(a)
注意:返回的是a中元素最大值所对应的索引值

一、函数说明

argmax(a, axis=None, out=None)
    Returns the indices of the maximum values along an axis.           #返回向量的最大值的索引

    Parameters
    ----------
    a : array_like
        Input array.
    axis : int, optional
        By default, the index is into the flattened array, otherwise
        along the specified axis.
    out : array, optional
        If provided, the result will be inserted into this array. It should
        be of the appropriate shape and dtype.

  返回元素最大值所对应的索引值!若还是没看明白,下面则是例子来辅助理解。
 

二、函数用法

1、一维数组

In :       	a = np.array([3,1,2,1,3,5])
Out: 		[3,1,2,1,3,5]

In : 		b = np.argmax(a)                        # 元素最大值的索引值      
Out: 		5    

2、二维数组

In :       	a = np.array([[1, 3, 5, 7],[5, 7, 2, 2],[4, 6, 8, 1]])
Out: 		[[1, 3, 5, 7],
             [5, 7, 2, 2],
             [4, 6, 8, 1]]

In : 		b = np.argmax(a, axis=0)						# 对数组按列方向搜索最大值                           
Out: 		[1 1 2 0]       

In : 		b = np.argmax(a, axis=1)						# 对数组按行方向搜索最大值                           
Out: 		[3 1 2]    
  • 13
    点赞
  • 36
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值