简体   繁体   English

python 中二维数组中间隔的最大值

[英]Max value in intervals in 2D array in python

I have data with 2D arrays with two columns.(first column height,second power)我有两列二维 arrays 的数据。(第一列高度,第二次幂)

arr1 = np.array([[30, 12.1], [30.2,12.5],[33, 12.4], [30.1,12.7],[34, 13.2], [35,13,7],[34, 13.2], [30.05,12.3],[30.05,12.7]])

I would like have intervals for height between 32 in 48 with step 0.3.我希望高度间隔在 32 到 48 之间,步长为 0.3。 For each interval I would like calculate maximum value for power.对于每个间隔,我想计算功率的最大值。

For example: I have interval for height example [30-30.3].例如:我有高度示例 [30-30.3] 的区间。 The maximum power for that interval is 12.7.该间隔的最大功率为 12.7。

In new 2D array I would like save 30.05 for column height(first column) and 12.7 for column power(second column).在新的二维数组中,我想为列高(第一列)保存 30.05,为列功率(第二列)保存 12.7。

import numpy as np
def maximum(arr, start,end):
    m = -1
    for i in arr:
        if(i[0]<=end and i[0]>=start):
            if(m<i[1]):
                m = i[1]
    return m
arr1 = np.array([[30, 12.1], [30.2,12.5],[33, 12.4], [30.1,12.7],[34, 13.2], [35,13.7],[34, 13.2], [30.05,12.3],[30.05,12.7]])
print(maximum(arr1,30,30.3))

I think this will help you in your desired output.我认为这将帮助您获得所需的 output。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM