繁体   English   中英

在二维数组的每一行中查找最大值的索引

[英]Find index of max value in each row of 2D array

我有以下代码:

amplitude=[]
for i in range (0,160):
    amplitude.append(i+1)

#print(amplitude)

#split arrays up into a line for each sample
traceno=10                  #number of traces in file
samplesno=16             #number of samples in each trace. This wont change.

amplitude_split=np.array(amplitude, dtype=np.int).reshape((traceno,samplesno))
print(amplitude_split)

#print the maximum value of array along axis=1
max_amp=np.amax(amplitude_split,1)
print(max_amp)

#print the  indices of the maximum values along axis=1
ind_max_amp=np.argmax(amplitude_split, axis=1, out=None)
print(ind_max_amp)

我想在数组的每一行中找到最大值的索引。 我目前只得到ind_max_amp = [15 15 15 15 15 15 15 15 15 15]我认为这是每个最大值的列。

我需要的是元组:(0,15)(1,15)等......

另外,谁能帮我找到每行最大 90% 和 10% 的索引?

注意这只是测试代码,我的真实数据的最大值不会都在最后一列

您可以通过np.amax使用axis=1keepdims获取每行的最大值,以将每个最大值保留在单独的行中,然后使用np.argwhere在每行中查找该最大值的索引。

这将为您提供所需的索引元组列表:

ind = np.argwhere(amplitude_split==np.amax(amplitude_split,1, keepdims=True))
list(map(tuple, ind))

output:

[(0, 15), (1, 15), (2, 15), (3, 15), (4, 15), (5, 15), (6, 15), (7, 15), (8, 15), (9, 15)]

暂无
暂无

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

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