我的数据如下:
data=array([ 0.56660112, 0.76309473, 0.69597908, 0.38260156, 0.24346445,
0.56021785, 0.24109326, 0.41884061, 0.35461957, 0.54398472,
0.59572658, 0.92377974])用户提供的索引数组(可以是可变的):
index=[3,5,7,11]maxima应该在3到5,5到7,7,11之间进行计算,类似wise,而且所有的maxima指数都应该附加在另一个列表中。
fa= [0.38260156, 0.24346445, 0.56021785]
sa= [0.56021785, 0.24109326, 0.41884061]
ta= [0.41884061, 0.35461957, 0.54398472, 0.59572658, 0.92377974]在内部,应根据索引大小进行拆分,并在列表中添加局部最大值的索引。
发布于 2017-03-25 09:25:25
numpy的argmax( array )函数将返回给定数组中最大值的索引。
maxValueInArray = np.argmax(data)要获取数组范围内的maxima索引,只需执行以下操作:
maxValueInRange = np.argmax(data[beginning:end]])然后循环遍历所有的索引范围,收集所有的maxima索引。然后,您可以在以后收集所有的实际值,就像您现在如何将它们的索引或附加到数组中一样,同时在极大值上循环。给定小大小数组(如示例中的数组),无论是哪种方式,性能都不会有明显的差异。
以下是遍历范围并在特定范围内追加maxima索引的一种方法:
from numpy import array
import numpy as np
maximaArray = []
data=array([ 0.56660112, 0.76309473, 0.69597908, 0.38260156, 0.24346445,
0.56021785, 0.24109326, 0.41884061, 0.35461957, 0.54398472,
0.59572658, 0.92377974])
index=[3,5,7,11]
for i in range(len(index)):
if i+1 == len(index):
break
maximaArray.append(np.argmax(data[index[i]:index[i+1]+1]))
>>> maximaArray
[2, 0, 4]2、0和4对应于这些数组中的索引:
fa= [0.38260156, 0.24346445, 0.56021785]
sa= [0.56021785, 0.24109326, 0.41884061]
ta= [0.41884061, 0.35461957, 0.54398472, 0.59572658, 0.92377974]https://stackoverflow.com/questions/43014653
复制相似问题