简体   繁体   English

如何修复索引数组中最大值的错误?

[英]How can I fix the error indexing the maximum in an array?

I'm trying to get the indexes of the maximums in an array, and put them into another array.我正在尝试获取数组中最大值的索引,并将它们放入另一个数组中。 'spc' is an array of 1994736 elements, that shows (around) 400 peaks periodically, and I'm trying to get the indexes of the odd-numbered peaks. 'spc' 是一个包含 1994736 个元素的数组,它定期显示(大约)400 个峰,我正在尝试获取奇数峰的索引。 'x' is the period of the peaks. 'x' 是峰值的周期。 I wrote this:我写了这个:

pms=np.zeros(201)
for k in range(1,200):
    pms[k]=np.where(spc==np.max(spc[(l>x*(2*k-1)-1000)&(l<x*(2*k-1)+1000)]))[0][0]

Once I run the code I obtain the following error:运行代码后,出现以下错误:

IndexError: boolean index did not match indexed array along dimension 0; dimension is 1994736 but corresponding boolean dimension is 1996776

Can somebody help me?有人可以帮我吗?

Your code seems weird: you want to find all peakes with this function:你的代码看起来很奇怪:你想用这个函数找到所有的峰:

spc[(l>x*(2*k-1)-1000)&(l<x*(2*k-1)+1000)]

using np.where使用 np.where

now, you want to find the max of elements that the "where" has found.现在,您想找到“where”找到的元素的最大值。

Correct?正确的?

So, this should be sth like:所以,这应该是这样的:

np.maximum(np.where ....)

Please ask your question in a clear way.请清楚地提出您的问题。 Based on what you told, I think your method is wrong.根据你所说的,我认为你的方法是错误的。

I fixed it, I was using an array 'l' which has a different dimension from the array 'spc'.我修复了它,我使用的数组“l”与数组“spc”具有不同的维度。 Now it works.现在可以了。

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

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