是否有一个 numpy 的“最大减去最小"?功能? [英] Is there a numpy "max minus min" function?

查看:63
本文介绍了是否有一个 numpy 的“最大减去最小"?功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一个 numpy 函数可以为给定的 numpy 数组提供其最大值 - 最小值,即 numpy.max(a) - numpy.min(a) ?

Is there a numpy function that gives for a given numpy array its maximum - minimum value, i.e. numpy.max(a) - numpy.min(a) ?

例如

numpy.xxx([4,3,2, 6] = 4 since max = 6, min = 2, 6 - 4 = 2)

原因:性能提升,因为 max 和 min 会导致数组迭代次数增加两倍(在我的情况下为 750 万或更多数字).

Reason: performance increase since max and min would cause twice the iteration of the array (which is in my case 7.5 million or more numbers).

推荐答案

确实有这样的功能——它叫做 numpy.ptp() 表示峰到峰".

Indeed there is such a function -- it's called numpy.ptp() for "peak to peak".

这篇关于是否有一个 numpy 的“最大减去最小"?功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆