p = []
for i in range(len(f)):
p.append(peakdetect(H, 0.1))
plt.plot(Freq[p], f)
因为整个代码很复杂所以我只附加了bug所在的部分。
我想绘制一张关于Freq和f的图表。 p是下面的索引,
[[126, 269, 409, 542],
[145, 288, 427, 558],
[162, 305, 443, 572],
[177, 320, 457],
[191, 334, 471],
[204, 347, 483],
[217, 359, 494],
[228, 370, 504],
[238, 380, 513],
[248, 389, 521],
[257, 398, 528],
[265, 406, 535],
[273, 414, 541],
[280, 421, 546],
[287, 428, 551],
[294, 434],
[300, 440],
[306, 445],
[312, 451],
[317, 455],
[322, 460],
[327, 464],
[331, 468],
[336, 472],
[340, 476],
[344, 479],
[348, 482],
[351, 486],
[355, 488],
[358, 491],
[361, 494],
[364, 496],
[367, 498],
[370, 500],
[373, 502],
[375, 504],
[378, 506],
[380, 507],
[383, 509],
[385, 510],
[387, 511],
[389, 512],
[392, 513],
[394, 514],
[395, 515],
[397, 515],
[399, 516],
[401, 516],
[403],
[404],
[406],
[408],
[409],
[411],
[412],
[413],
[415],
[416],
[417],
[419],
[420]]
其中,
f[0] corresponds to [126, 269, 409, 542]
f[1] corresponds to [145, 288, 427, 558]
f[2] corresponds to [162, 305, 443, 572]
f[3] corresponds to [177, 320, 457]
f[4] corresponds to [191, 334, 471]
...
你看,列表p没有完成4列,所以当我运行它时,它显示错误:只有整数,切片(:
),省略号({{1} }),numpy.newaxis(...
)和整数或布尔数组是有效索引。
所以我认为一种方法是使用None完成列的其余部分,但我不确定。另一种方法是使用列表字符对列进行切片,但难以操作。
peakdetect(H,0.1)是一个自定义函数。不用担心。