欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 科技 > IT业 > python numpy 函数参数详解

python numpy 函数参数详解

2025/5/11 18:15:43 来源:https://blog.csdn.net/qq_41768644/article/details/144199983  浏览:    关键词:python numpy 函数参数详解

一、np.unique()

newar=unique(oldar, return_index=False, return_inverse=False, return_counts=False, axis=None, *, equal_nan=True)

1.1 简介

对于一维数组或者列表,np.unique() 函数 去除其中重复的元素 ,并按元素 由小到大 返回一个新的无元素重复的元组或者列表。

1.2 参数详解

旧列表是指参数值oldar,新列表是指unique函数的返回值 newar

  • ar 待输入的数组
  • return_index=False 如果为 True,返回新列表元素在旧列表中的位置(下标),并以列表形式存储。
  • return_inverse=False 如果为True,返回旧列表元素在新列表中的位置(下标),并以列表形式存储。
  • return_counts:如果为 True,返回新数组中的元素在原数组中的出现次数。

1.3 实例

>>> a=[1,2,2,3,5,6,7,8,4,4,9]
>>> new_a , a_index ,a_inverse = np.unique(a,return_index=True,return_inverse=True)
>>>
>>>
>>>
>>> print(new_a)
[1 2 3 4 5 6 7 8 9]
>>> print(a_index)
[ 0  1  3  9  5  6  7  8 11]
>>> print(a_inverse)
[0 1 1 2 2 4 5 6 7 3 3 8]
>>>
>>>> new_a , a_index ,a_inverse ,a_count= np.unique(a,return_index=True,retur
n_inverse=True,return_counts=True)
>>> print(a_count)
[1 2 2 2 1 1 1 1 1]
>>>

二、np.argmax()

argmax(a, axis=None, out=None, *, keepdims=<no value>)

返回a数组中最大值的索引(最靠前的索引),

>>> max=[1,2,5,3,3,4,4,4,5,4,4,5]
>>> print(np.argmax(max))
2
>>>

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词