找到非常高的多峰元素,留下其余的低峰
Finding very high multiple peak element leaving the rest low peaks
我有一堆值存储在一个数组中,我需要找到最高峰。我尝试使用此代码:
arr=["values"]
n=len(arr)
if arr == []:
print (pos)
Diff = []
for i in range(0,n-1):
if arr[i]< arr[i+1]:
Diff.append(1)
elif arr[i] == arr[i+1]:
Diff.append(0)
if arr[i] > arr[i+1]:
Diff.append(-1)
pos = []
peaks = []
j = 0
for i in range(0,n-2):
if Diff[i] == 1 and Diff[i+1] == -1:
pos.append(i+1)
peaks.append(arr[i+1])
if Diff[i] == 1 and Diff[i+1] == 0:
if Diff[i+1:] == [Diff[i+1]]:
break
j = i+1
while(Diff[j] == 0 and j < n-2):
j = j+1
if Diff[j] == -1:
pos.append(i+1)
peaks.append(arr[i+1])
print (pos)
print (peaks)
但是我得到的是所有的峰,我正在尝试解决以单独获得最高峰。
我的数据是:
A=['5662', '5660', '5658', '5658', '5658', '5658', '5655', '5653', '5655', '5660', '5664', '5664', '5662', '5655', '5655', '5655', '5658', '5664', '5674', '5685', '5694', '5699', '5701', '5704', '5706', '5708', '5704', '5701', '5704', '5708', '5713', '5720', '5720', '5724', '5733', '5745', '5761', '5777', '5798', '5819', '5832', '5842', '5846', '5851', '5858', '5862', '5865', '5869', '5874', '5874', '5867', '5855', '5851', '5855', '5865', '5874', '5878', '5883', '5888', '5892', '5897', '5899', '5901', '5901', '5904', '5899', '5894', '5890', '5894', '5899', '5904', '5904', '5894', '5881', '5860', '5839', '5823', '5814', '5809', '5805', '5798', '5791', '5786', '5782', '5779', '5777', '5775', '5773', '5775', '5777', '5779', '5779', '5773', '5763', '5752', '5745', '5740', '5738', '5729', '5717', '5701', '5687', '5678', '5674', '5664', '5653', '5646', '5646', '5651', '5655', '5655', '5653', '5651', '5646', '5646', '5646', '5648', '5653', '5653', '5653', '5653', '5655', '5662', '5664', '5660', '5651', '5648', '5651', '5658', '5662', '5662', '5660', '5658', '5653', '5648', '5648', '5653', '5658', '5658', '5658', '5658', '5662', '5667', '5664', '5658', '5651', '5653', '5655', '5658', '5660', '5662', '5664', '5664', '5660', '5655', '5658', '5664', '5667', '5667', '5664', '5667', '5669', '5669', '5664', '5660', '5658', '5660', '5662', '5664', '5669', '5674', '5674', '5669', '5664', '5662', '5660', '5660', '5658', '5658', '5662', '5669', '5671', '5669', '5662', '5660', '5660', '5664', '5664', '5667', '5667', '5667', '5664', '5660', '5660', '5662', '5664', '5664', '5664', '5667', '5671', '5676', '5674', '5669', '5667', '5664', '5662', '5660', '5662', '5667', '5671', '5674', '5671', '5669', '5669', '5671', '5671', '5669', '5667', '5669', '5674', '5676', '5678', '5676', '5674', '5669', '5669', '5671', '5676', '5678', '5676', '5676', '5676', '5674', '5674', '5669', '5667', '5667', '5669', '5674', '5676', '5676', '5676', '5676', '5671', '5669', '5667', '5667', '5671', '5676', '5676', '5674', '5674', '5676', '5678', '5678', '5674', '5671', '5674', '5678', '5681', '5683', '5683', '5681', '5678', '5674', '5671', '5676', '5681', '5685', '5685', '5683', '5683', '5685', '5683', '5678', '5671', '5671', '5674', '5681', '5683', '5683', '5685', '5694', '5701', '5706', '5706', '5708', '5713', '5720', '5727', '5729', '5733', '5731', '5724', '5717', '5715', '5717', '5724', '5727', '5727', '5727', '5727', '5727', '5724', '5720', '5713', '5713', '5715', '5715', '5713', '5708', '5701', '5694', '5687', '5681', '5676', '5678', '5681', '5681', '5676', '5674', '5676', '5681', '5678', '5674', '5669', '5671', '5676', '5683', '5683', '5685', '5685', '5683', '5678', '5674', '5676', '5681', '5687', '5687', '5683', '5678', '5676', '5681', '5683', '5685', '5685', '5683', '5681', '5681', '5678', '5681', '5678', '5678', '5681', '5690', '5708', '5736', '5766', '5798', '5830', '5871', '5924', '5984', '6044', '6106', '6175', '6262', '6359', '6456', '6543', '6614', '6667', '6688', '6663', '6589', '6488', '6382', '6281', '6175', '6060', '5943', '5839', '5763', '5708', '5660', '5623', '5602', '5602', '5609', '5612', '5612', '5612', '5616', '5625', '5635', '5641', '5648', '5655', '5660', '5664', '5664', '5662', '5662', '5664', '5664', '5667', '5664', '5662', '5662', '5667', '5671', '5676', '5671', '5662', '5658', '5662', '5671', '5676', '5676', '5671', '5669', '5671', '5671', '5671', '5664', '5660', '5660', '5667', '5674', '5681', '5681', '5681', '5681', '5685', '5692', '5697', '5701', '5704', '5708', '5715', '5717', '5715', '5715', '5715', '5713', '5710', '5710', '5717', '5733', '5750', '5761', '5773', '5786', '5805', '5823', '5837', '5846', '5853', '5865', '5876', '5883', '5885', '5885', '5883', '5876', '5869', '5865', '5862', '5871', '5881', '5888', '5894', '5897', '5899', '5901', '5901', '5904', '5906', '5908', '5911', '5911', '5908', '5908', '5908', '5904', '5899', '5897', '5897', '5897', '5888', '5869', '5846', '5828', '5816', '5812', '5805', '5798', '5793', '5796', '5796', '5796', '5796', '5793', '5789', '5786', '5782', '5779', '5779', '5775', '5768', '5759', '5754', '5747', '5738', '5720', '5699', '5685', '5678', '5681', '5681', '5678', '5671', '5667', '5664', '5660', '5658', '5660', '5667', '5671', '5671', '5669', '5669', '5669', '5667', '5664', '5658', '5658', '5662', '5664', '5664', '5664', '5664', '5664', '5662', '5658', '5658', '5660', '5667', '5669', '5667', '5662', '5662', '5664', '5669', '5667', '5660', '5658', '5660', '5667', '5674', '5676', '5676', '5671', '5664', '5658', '5658', '5664', '5671', '5674', '5671', '5669', '5667', '5667', '5664', '5664', '5662', '5662', '5667', '5669', '5676', '5676', '5674', '5671', '5669', '5671', '5674', '5671', '5667', '5667', '5671', '5678', '5681', '5676', '5669', '5667', '5669', '5671', '5674', '5676', '5678', '5681', '5681', '5676', '5671', '5669', '5671', '5674', '5676', '5676', '5681', '5683', '5685', '5685', '5683', '5676', '5671', '5671', '5674', '5681', '5683', '5681', '5678', '5674', '5674', '5674', '5676', '5678', '5678', '5678', '5678', '5681', '5685', '5685', '5681', '5674', '5669', '5671', '5676', '5681', '5683', '5681', '5681', '5678', '5676', '5674', '5676', '5678', '5678', '5678', '5678', '5681', '5683', '5681', '5676', '5669', '5671', '5676', '5681', '5681', '5683', '5683', '5685', '5685', '5683', '5681', '5681', '5683', '5685', '5685', '5683', '5685', '5685', '5683', '5678', '5676', '5681', '5685', '5687', '5685', '5687', '5690', '5690', '5687', '5683', '5678', '5678', '5678', '5681', '5683', '5687', '5692', '5690', '5683', '5674', '5674', '5683', '5694', '5704', '5710', '5715', '5722', '5727', '5729', '5729', '5727', '5727', '5727', '5727', '5729', '5733', '5736', '5736', '5731', '5727', '5727', '5729', '5733', '5731', '5729', '5729', '5733', '5736', '5733', '5724', '5713', '5706', '5701', '5699', '5694', '5692', '5690', '5690', '5687', '5685', '5685', '5685', '5685', '5685', '5685', '5687', '5687', '5690', '5685', '5678', '5669', '5667', '5669', '5678', '5687', '5692', '5694', '5690', '5685', '5683', '5683', '5685', '5683', '5681', '5681', '5683', '5690', '5692', '5692', '5687', '5683', '5676', '5676', '5681', '5692', '5706', '5722', '5745', '5768', '5798', '5828', '5867', '5917', '5977', '6042', '6108', '6187', '6276', '6377', '6469', '6548', '6607', '6658', '6688', '6679', '6617', '6513', '6396', '6285', '6173', '6058', '5940', '5842', '5768', '5717', '5678', '5646', '5621', '5612', '5607', '5605', '5605', '5609', '5623', '5637', '5646', '5653', '5658', '5664', '5667', '5667', '5664', '5660', '5662', '5664', '5671', '5674', '5674', '5671', '5667', '5664', '5667', '5669', '5671', '5674', '5676', '5676', '5676', '5674', '5671', '5674', '5674', '5671', '5667', '5667', '5676', '5683', '5685', '5676', '5669', '5671', '5681', '5685', '5685', '5685', '5692', '5708', '5720', '5722', '5717', '5713', '5717', '5722', '5724', '5724', '5727', '5731', '5731', '5729', '5731', '5743', '5759', '5779', '5791', '5805', '5823', '5844', '5860', '5867', '5862', '5860', '5865', '5876', '5890', '5894', '5892', '5883', '5876', '5874', '5876', '5883', '5892', '5899', '5906', '5908', '5911', '5913', '5915', '5917', '5915', '5908', '5904', '5908', '5917', '5924', '5924', '5915', '5911', '5906', '5901', '5885', '5862', '5839', '5825', '5816', '5812', '5807', '5805', '5802', '5798', '5793', '5791', '5793', '5798', '5800', '5798', '5793', '5791', '5786', '5777', '5768', '5761', '5759', '5754', '5743', '5729', '5717', '5708', '5697', '5681', '5669', '5667', '5671', '5674', '5671', '5671', '5671', '5674', '5671', '5667', '5662', '5664', '5667', '5667', '5664', '5667', '5674', '5678', '5674', '5664', '5660', '5660', '5664', '5667', '5667', '5667', '5669', '5674', '5671', '5667', '5664', '5667', '5671', '5674', '5674', '5674', '5676', '5681', '5676', '5671', '5664', '5667', '5674', '5676', '5674', '5671', '5671', '5678', '5683', '5678', '5667', '5662', '5669', '5678', '5681', '5676', '5674', '5676', '5678', '5674', '5667', '5664', '5669', '5678', '5681', '5676', '5674', '5674', '5678', '5678', '5676', '5671', '5676', '5681', '5683', '5683', '5678', '5676', '5674', '5671', '5669', '5669', '5667', '5669', '5669', '5671', '5676', '5681', '5681', '5678', '5671', '5669', '5671', '5676', '5681', '5685', '5681', '5676', '5671', '5671', '5674', '5681', '5681', '5681', '5678', '5683', '5690', '5692', '5687', '5678', '5669', '5722', '5729', '5733', '5738', '5740', '5738', '5736', '5733', '5736', '5738', '5745', '5747', '5747', '5745', '5740', '5738', '5733', '5733', '5736', '5743', '5750', '5752', '5745', '5736', '5724', '5717', '5713', '5706', '5699', '5694', '5690', '5692', '5694', '5697', '5697', '5692', '5687', '5683', '5683', '5687', '5692', '5694', '5694', '5692', '5690', '5685', '5685', '5685', '5690', '5694', '5697', '5699', '5701', '5701', '5697', '5692', '5685', '5683', '5690', '5694', '5699', '5699', '5699', '5701', '5699', '5692', '5683', '5678', '5685', '5701', '5722', '5745', '5773', '5802', '5832', '5867', '5913', '5968', '6035', '6104', '6177', '6262', '6359', '6458', '6543', '6610', '6658', '6686', '6679', '6624', '6529', '6419', '6313', '6205', '6090', '5968', '5860', '5779', '5727', '5687', '5653', '5625', '5614', '5618', '5623', '5621', '5616', '5618', '5632', '5651', '5662', '5669', '5671', '5671', '5671', '5676', '5678', '5681', '5678', '5674', '5676', '5681', '5687', '5690', '5687', '5683', '5676', '5669', '5669', '5674', '5681', '5687', '5690', '5685', '5681', '5678', '5678', '5678', '5674', '5674', '5676', '5681', '5683', '5683', '5678', '5681', '5683', '5685', '5690', '5701', '5713', '5724', '5729', '5729', '5729', '5727', '5729', '5729', '5729', '5729', '5731', '5733', '5740', '5752', '5761', '5768', '5773', '5784', '5802', '5828', '5848', '5862', '5867', '5871', '5876', '5883', '5888', '5888', '5888', '5885', '5883', '5881', '5878', '5881', '5885', '5894', '5901', '5906', '5911', '5911', '5915', '5917', '5922', '5922', '5920', '5915', '5911', '5911', '5913', '5915', '5920', '5920', '5920', '5911', '5892', '5869', '5848', '5835', '5828', '5823', '5819', '5812', '5807', '5805', '5802', '5802', '5800', '5796', '5791', '5791', '5796', '5800', '5800', '5789', '5773', '5763', '5761', '5763', '5759', '5743', '5724', '5706', '5699', '5697', '5692', '5685', '5676', '5669', '5667', '5669', '5674', '5681', '5685', '5685', '5683', '5678', '5674', '5669', '5669', '5671', '5674', '5674', '5674', '5671', '5671', '5669', '5667', '5667', '5667', '5671', '5678', '5681', '5681', '5678', '5674', '5671', '5667', '5669', '5671', '5676', '5676', '5676', '5676', '5681', '5685', '5683', '5676', '5669', '5669', '5678', '5687', '5690', '5687', '5683', '5678', '5678', '5678', '5683', '5685', '5683', '5681', '5681', '5683', '5687', '5690', '5685', '5678', '5676', '5676', '5678', '5683', '5687', '5687', '5685', '5681', '5676', '5676', '5678', '5681', '5681', '5678', '5681', '5687', '5690', '5685', '5676', '5671', '5674', '5678', '5683', '5683', '5683', '5685', '5687', '5685', '5681', '5676', '5678', '5683', '5685', '5683', '5683', '5687', '5692', '5692', '5687', '5681', '5681', '5685', '5690', '5692', '5690', '5687', '5687', '5687', '5685', '5683', '5681', '5683', '5685', '5687', '5687', '5690', '5690', '5685', '5681', '5678', '5681', '5685', '5687', '5687', '5687', '5690', '5692', '5692', '5690', '5685', '5681', '5681', '5681', '5685', '5690', '5692', '5694', '5690', '5685', '5683', '5685', '5692', '5694', '5694', '5694', '5694', '5697', '5694', '5690', '5685', '5685', '5687', '5690', '5692', '5694', '5697', '5694', '5692', '5687', '5685', '5685', '5687', '5692', '5692', '5692', '5694', '5694', '5694', '5692', '5690', '5687', '5687', '5690', '5694', '5706', '5715', '5720', '5717', '5715', '5717', '5722', '5729', '5733', '5733', '5733', '5738', '5740', '5738', '5733', '5731', '5733', '5736', '5738', '5740', '5743', '5747', '5747', '5743', '5736', '5733', '5738', '5738', '5729', '5717', '5708', '5708', '5713', '5706', '5694', '5685', '5683', '5690', '5697', '5697', '5694', '5690', '5690', '5690', '5690', '5690', '5687', '5690', '5690', '5690', '5692', '5694', '5694', '5692', '5692', '5690', '5687', '5687', '5692', '5697', '5701', '5697', '5692', '5690', '5692', '5697', '5697', '5694', '5694', '5697', '5699', '5699', '5699', '5706', '5722', '5740', '5761', '5786', '5819', '5860', '5911', '5966', '6026', '6088', '6157', '6237', '6331', '6428', '6520', '6596', '6653', '6690', '6688', '6640', '6550', '6440', '6329', '6226', '6118', '6005', '5894', '5805', '5743', '5697', '5658', '5625', '5609', '5607', '5609', '5614', '5621', '5632', '5641', '5646', '5646', '5651', '5662', '5676', '5681', '5678', '5676', '5678', '5683', '5681', '5676', '5671', '5674', '5676', '5678', '5676', '5676', '5678', '5681', '5678', '5674', '5674', '5678', '5683', '5681', '5678', '5678', '5681', '5683', '5681', '5674', '5671', '5676', '5685', '5687', '5690', '5690', '5694', '5701', '5704', '5704', '5708', '5717', '5727', '5729', '5727', '5724', '5729', '5736', '5736', '5729', '5722', '5724', '5736', '5752', '5768', '5784', '5800', '5814', '5828', '5842', '5858', '5869', '5874', '5874', '5874', '5883', '5899', '5908', '5899', '5881', '5865', '5865', '5874', '5888', '5899', '5906', '5908', '5911', '5908', '5906', '5911', '5917', '5922', '5922', '5917', '5917', '5920', '5924', '5922', '5915', '5908', '5906', '5904', '5899', '5885', '5865', '5844', '5830', '5821', '5816', '5807', '5800', '5798', '5802', '5807', '5807', '5802', '5800', '5800', '5800', '5796', '5789', '5779', '5777', '5775', '5773', '5763', '5750', '5738', '5724', '5708', '5694', '5685', '5683', '5685', '5685', '5683', '5681', '5678', '5676', '5674', '5674', '5676', '5683', '5687', '5683', '5676', '5674', '5674', '5676', '5676', '5671', '5669', '5671', '5674', '5678', '5678', '5678', '5674', '5669', '5667', '5669', '5674', '5678', '5678', '5676', '5676', '5678', '5681', '5676', '5667', '5660', '5664', '5674', '5683', '5685', '5681', '5678', '5676', '5674', '5671', '5674', '5676', '5681', '5681', '5681', '5681', '5683', '5683', '5681', '5676', '5676', '5678', '5681', '5681', '5683', '5685', '5685', '5681', '5676', '5676', '5681', '5685', '5685', '5683', '5683', '5685', '5685', '5683', '5678', '5674', '5674', '5678', '5681', '5681', '5678', '5681', '5683', '5685', '5681', '5676', '5676', '5681', '5683', '5685', '5687', '5690', '5690', '5687', '5681', '5676', '5676', '5683', '5687', '5690', '5687', '5685', '5685', '5685', '5683', '5681', '5681', '5683', '5685', '5687', '5685', '5687', '5690', '5690', '5683', '5678', '5678', '5685', '5690', '5692', '5687', '5685', '5690', '5690', '5687', '5683', '5681', '5683', '5687', '5690', '5694', '5694', '5694', '5690', '5685', '5683', '5685', '5690', '5694', '5697', '5694', '5694', '5694', '5692', '5694', '5694', '5692', '5690', '5690', '5694', '5697', '5697', '5694', '5687', '5683', '5681', '5683', '5687', '5687', '5690', '5690', '5690', '5690', '5687', '5687', '5687', '5692', '5694', '5694', '5692', '5690', '5692', '5692', '5690', '5685', '5685', '5692', '5701', '5715', '5722', '5727', '5729', '5731', '5733', '5736', '5731', '5729', '5729', '5731', '5738', '5743', '5740', '5738', '5736', '5738', '5740', '5745', '5745', '5743', '5740', '5743', '5747', '5745', '5736', '5722', '5710', '5704', '5701', '5701', '5701', '5701', '5699', '5697', '5694', '5690', '5692', '5694', '5697', '5697', '5697', '5699', '5699', '5697', '5692', '5687', '5685', '5687', '5692', '5694', '5699', '5701', '5704', '5699', '5694', '5690', '5687', '5690', '5692', '5694', '5701', '5704', '5708', '5706', '5699', '5687', '5678', '5676', '5685', '5701', '5720', '5738', '5759', '5786', '5816', '5851', '5890', '5943', '6003', '6069', '6138', '6219', '6308', '6410', '6502', '6575', '6630', '6674', '6690', '6665', '6589', '6479', '6359', '6249', '6138', '6026', '5915', '5819', '5745', '5692', '5653', '5628', '5618', '5621', '5621', '5614', '5607', '5609', '5628', '5651', '5664', '5667', '5664', '5662', '5667', '5671', '5674', '5669', '5667', '5664', '5671', '5683', '5690', '5687', '5678', '5669', '5664', '5667', '5671', '5676', '5678', '5681', '5678', '5676', '5678', '5678', '5678', '5676', '5676', '5676', '5681', '5681', '5683', '5681', '5678', '5676', '5676', '5683', '5692', '5704', '5710', '5717', '5720', '5724', '5729', '5727', '5722', '5717', '5720', '5724', '5733', '5738', '5740', '5740', '5743', '5752', '5763', '5779', '5800', '5821', '5842', '5853', '5862', '5867', '5871', '5878', '5883', '5888', '5885', '5885', '5885', '5883', '5883', '5881', '5881', '5885', '5897', '5906', '5911', '5911', '5911', '5915', '5922', '5922', '5915', '5911', '5906', '5911', '5913', '5915', '5915', '5917', '5917', '5908', '5894', '5874', '5855', '5844', '5835', '5823', '5816', '5814', '5814', '5809', '5805', '5796', '5793', '5796', '5800', '5802', '5800', '5800', '5798', '5791', '5782', '5770', '5763', '5759', '5752', '5745', '5731', '5720', '5708', '5694', '5683', '5671', '5671', '5671', '5669', '5667', '5667', '5669', '5674', '5674', '5669', '5667', '5669', '5676', '5678', '5676', '5674', '5674', '5681', '5685', '5681', '5671', '5664', '5667', '5674', '5681', '5683', '5683', '5681', '5683', '5683', '5681', '5678', '5678', '5681', '5681', '5681', '5683', '5683', '5683', '5676', '5667', '5664', '5671', '5683', '5687', '5683', '5674', '5671', '5678', '5683', '5683', '5671', '5662', '5662', '5669', '5681', '5687', '5685', '5678', '5674', '5674', '5674', '5678', '5683', '5685', '5685', '5683', '5683', '5681', '5681', '5681', '5676', '5674', '5674', '5678', '5685', '5687', '5683', '5678', '5678', '5681', '5681', '5678', '5674', '5674', '5678', '5685', '5687', '5683', '5678', '5676', '5676', '5678', '5681', '5685', '5687', '5690', '5690', '5687', '5685', '5681', '5678', '5678', '5681', '5683', '5681', '5683', '5685', '5687', '5685', '5681', '5676', '5678', '5685', '5690', '5692', '5692', '5692', '5692', '5685', '5678', '5676', '5681', '5687', '5690', '5687', '5685', '5690', '5694', '5692', '5687', '5681', '5683', '5687', '5692', '5692', '5690', '5685', '5683', '5681', '5681', '5685', '5690', '5690', '5685', '5685', '5690', '5697', '5697', '5687', '5681', '5678', '5685', '5692', '5694', '5694', '5697', '5697', '5694', '5690', '5687', '5690', '5694', '5694', '5692', '5692', '5694', '5701', '5701', '5692', '5681', '5676', '5681', '5687', '5690', '5692', '5692', '5701', '5710', '5717', '5720', '5720', '5724', '5731', '5736', '5738', '5740', '5743', '5745', '5740', '5733', '5729', '5733', '5743', '5745', '5743', '5738', '5738', '5743', '5743', '5738', '5731', '5729', '5731', '5733', '5731', '5727', '5720', '5710', '5701', '5692', '5687', '5690', '5697', '5701', '5699', '5694', '5694', '5694', '5697', '5694', '5690', '5690', '5692', '5699', '5701', '5701', '5697', '5694', '5694', '5694', '5692', '5690', '5692', '5694', '5694', '5690', '5683', '5685', '5692', '5701', '5699', '5694', '5692', '5694', '5699', '5699', '5694', '5694', '5699', '5710', '5727', '5750', '5777', '5809', '5846', '5890', '5940', '5998', '6055', '6118', '6191', '6283', '6384', '6483', '6564', '6626', '6670', '6686', '6663', '6594', '6490', '6380', '6279', '6175', '6062', '5945', '5846', '5770', '5717', '5671', '5635', '5614', '5614', '5623', '5625', '5621', '5618', '5625', '5639', '5651', '5658', '5660', '5664', '5671', '5676', '5676', '5676', '5676', '5676', '5671', '5667', '5667', '5671', '5681', '5685', '5683', '5681', '5678', '5678', '5676', '5674', '5674', '5681', '5685', '5687', '5681', '5676', '5676', '5676', '5676', '5674', '5674', '5678', '5685', '5687', '5687', '5687', '5692', '5701', '5708', '5713', '5715', '5720', '5727', '5733', '5733', '5731', '5727', '5724', '5727', '5729', '5733', '5740', '5747', '5759', '5773', '5784', '5798', '5814', '5830', '5844', '5853', '5858', '5865', '5876', '5890', '5901', '5899', '5888', '5876', '5869', '5869', '5874', '5881', '5888', '5897', '5904', '5906', '5908', '5908', '5911', '5913', '5917', '5917', '5920', '5922', '5924', '5922', '5915', '5911', '5911', '5915', '5915', '5904', '5885', '5867', '5853', '5839', '5828', '5814', '5807', '5805', '5807', '5809', '5807', '5807', '5809', '5807', '5798', '5789', '5786', '5791', '5791', '5786', '5775', '5766', '5761', '5761', '5750', '5733', '5715', '5704', '5697', '5694', '5687', '5683', '5676', '5671', '5667', '5664', '5664', '5667', '5671', '5674', '5676', '5676', '5681', '5678', '5676', '5671', '5671', '5674', '5678', '5678', '5678', '5676', '5678', '5676', '5674', '5669', '5669', '5669', '5671', '5671', '5674', '5676', '5678', '5676', '5669', '5662', '5662', '5669', '5678', '5681', '5676', '5676', '5674', '5674', '5674', '5674', '5674', '5676', '5674', '5674', '5676', '5685', '5690', '5685', '5676', '5669', '5669', '5676', '5681', '5681', '5678', '5678', '5678', '5676', '5674', '5671', '5671', '5674', '5678', '5683', '5683', '5683', '5683', '5681', '5678', '5676', '5676', '5676', '5681', '5683', '5685', '5687', '5687', '5687', '5685', '5685', '5685', '5685', '5685', '5685', '5687', '5690', '5690', '5690', '5683', '5678', '5676', '5685', '5694', '5697', '5690', '5683', '5681', '5687', '5692', '5685', '5678', '5676', '5678', '5687', '5690', '5690', '5690', '5685', '5681', '5676', '5676', '5683', '5687', '5690', '5687', '5687', '5692', '5692', '5690', '5683', '5681', '5683', '5690', '5692', '5692', '5692', '5692', '5690', '5687', '5683', '5683', '5685', '5690', '5692', '5694', '5699', '5699', '5697', '5690', '5685', '5685', '5687', '5687', '5685', '5683', '5685', '5690', '5690', '5687', '5685', '5687', '5692', '5692', '5692', '5692', '5694', '5697', '5694', '5690', '5683', '5683', '5685', '5690', '5697', '5697', '5694', '5687', '5681', '5681', '5685', '5692', '5701', '5706', '5713', '5722', '5733', '5738', '5740', '5738', '5733', '5733', '5736', '5740', '5743', '5745', '5740', '5738', '5736', '5733', '5736', '5740', '5740', '5740', '5738', '5738', '5743', '5745', '5743', '5733', '5720', '5713', '5710', '5708', '5704', '5697', '5692', '5692', '5692', '5690', '5687', '5687', '5690', '5692', '5694', '5697', '5699', '5701', '5699', '5694', '5690', '5690', '5690', '5694', '5699', '5701', '5701', '5699', '5692', '5687', '5685', '5685', '5685', '5687', '5692', '5701', '5706', '5704', '5692', '5683', '5683', '5687', '5692', '5690', '5694', '5706', '5727', '5752', '5777', '5800', '5830', '5869', '5920', '5980', '6046', '6115', '6191', '6274', '6366', '6458', '6543', '6614', '6667', '6695', '6683', '6621', '6525', '6414', '6306', '6200', '6085', '5963', '5855', '5775', '5727', '5687', '5651', '5623', '5614', '5616', '5618', '5616', '5616', '5628', '5646', '5662', '5669', '5669', '5671', '5674', '5674', '5669', '5669', '5674', '5681', '5685', '5681', '5676', '5671', '5671', '5674', '5676', '5678', '5681', '5681', '5681', '5683', '5685', '5687', '5683', '5674', '5669', '5671', '5678', '5685', '5685', '5683', '5678', '5681', '5685', '5687', '5687', '5687', '5687', '5694', '5704', '5713', '5722', '5727', '5727', '5722', '5722', '5722', '5727', '5731', '5733', '5736', '5736', '5736', '5738', '5747', '5759', '5775', '5796', '5814', '5830', '5846', '5858', '5865', '5867', '5867', '5871', '5883', '5894', '5899', '5892', '5881', '5874', '5874', '5885', '5892', '5899', '5904', '5908', '5913', '5917', '5922', '5927', '5924', '5920', '5913', '5911', '5913', '5922', '5927', '5924', '5920', '5917', '5913', '5901', '5885', '5867', '5853', '5842', '5832', '5825', '5819', '5812', '5802', '5798', '5798', '5798', '5800', '5798', '5793', '5793', '5798', '5802', '5798', '5782', '5768', '5761', '5763', '5763', '5756', '5743', '5727', '5715', '5704', '5692', '5681', '5676', '5676', '5681', '5678', '5674', '5669', '5669', '5671', '5669', '5664', '5662', '5667', '5671', '5676', '5676', '5676', '5676', '5676', '5671', '5669', '5667', '5671', '5678', '5683', '5681', '5678', '5678', '5676', '5674', '5671', '5669', '5671', '5674', '5674', '5674', '5674', '5674', '5674', '5671', '5674', '5678', '5681', '5678', '5674', '5676', '5681', '5687', '5687', '5678', '5671', '5669', '5674', '5674', '5676', '5678', '5683', '5683', '5676', '5667', '5667', '5674', '5683', '5685', '5678', '5676', '5678', '5683', '5683', '5676', '5671', '5671', '5676', '5683', '5687', '5690', '5687', '5685', '5681', '5676', '5676', '5678', '5678', '5678', '5681', '5685', '5690', '5690', '5683', '5678', '5674', '5676', '5683', '5687', '5692', '5692', '5690', '5687', '5683', '5681', '5681', '5683', '5683', '5683', '5683', '5685', '5687', '5687', '5683', '5676', '5676', '5678', '5685', '5690', '5690', '5690', '5687', '5685', '5683', '5683', '5685', '5685', '5690', '5690', '5690', '5692', '5694', '5694', '5694', '5690', '5685', '5685', '5687', '5690', '5692', '5690', '5685', '5683', '5683', '5683', '5685', '5685', '5685', '5687', '5692', '5694', '5697', '5699', '5697', '5692', '5687', '5687', '5692', '5697', '5699', '5697', '5692', '5692', '5697', '5697', '5692', '5685', '5683', '5690', '5699', '5706', '5704', '5697', '5690', '5685', '5683', '5685', '5690', '5694', '5694', '5692', '5692', '5697', '5706', '5710', , '5860', '5862', '5865', '5869', '5878', '5888', '5892', '5892', '5890', '5883', '5878', '5874', '5876', '5883', '5890', '5899']
请帮忙。
首先,将您的字符串列表转换为 numpy 数组 或 pandas 系列:
import pandas as pd
s = pd.Series(A).astype(int)
其次,找出所有的极值(例如分布的极值1%),最后通过连续的值(峰值)得到最大值。我们可以很容易地识别连续的组 more_itertools.consecutive_groups
:
from more_itertools import consecutive_groups
grp_peaks = consecutive_groups(s[s >= s.quantile(.99)].index)
max_peaks = [s[grp].idxmax() for grp in grp_peaks]
print(s[max_peaks])
输出:
372 6688
787 6688
1132 6686
1547 6690
1963 6690
2378 6686
2793 6695
dtype: int64
数据可视化:
import matplotlib.pyplot as plt
plt.figure(figsize=(12,8))
plt.plot(s, marker='o')
# Set a line delimiting the extreme 1% values of the distribution
plt.axhline(y=s.quantile(.99), color='r', linestyle='--')
# Identify the maximum value per peak
plt.plot(s[max_peaks], color='r', marker='o', linestyle='None')
plt.show()
无需导入任何库即可重现上述结果的方法:
# Convert list of strings to integers and get respective indexes
A = list(map(int, A))
idx = range(len(A))
# Calculate empirical p-values to get the peaks
pval = [1 - sum([i >= j for j in A]) / (len(A)+1) for i in A]
# Identify extreme values (peaks)
stat_pval = [idx for idx,p in enumerate(pval) if p <= 0.01]
# Identify consecutive indexes in target
grps = []
consec_idx = []
stat_pval.append(stat_pval[-1]+2)
for i in range(len(stat_pval)-1):
if stat_pval[i] == stat_pval[i+1]-1:
consec_idx.append(stat_pval[i])
else:
consec_idx.append(stat_pval[i])
grps.append(consec_idx)
consec_idx = []
del consec_idx
del stat_pval[-1]
# Then, identify the maximum value per peak:
[max(A[grp[0]:grp[-1]+1]) for grp in grps]
[6688, 6688, 6686, 6690, 6690, 6686, 6695]
或者,如果您想打印每个峰的最大值及其索引:
idx_and_max_per_peak = []
for grp in grps:
peak = A[grp[0]:grp[-1]+1]
peak_max = max(peak)
idx_and_max_per_peak.extend([(grp[i], value) for i,value in enumerate(peak) if value==peak_max])
idx_and_max_per_peak
的输出:
[(372, 6688),
(787, 6688),
(1132, 6686),
(1547, 6690),
(1963, 6690),
(2378, 6686),
(2793, 6695)]
我有一堆值存储在一个数组中,我需要找到最高峰。我尝试使用此代码:
arr=["values"]
n=len(arr)
if arr == []:
print (pos)
Diff = []
for i in range(0,n-1):
if arr[i]< arr[i+1]:
Diff.append(1)
elif arr[i] == arr[i+1]:
Diff.append(0)
if arr[i] > arr[i+1]:
Diff.append(-1)
pos = []
peaks = []
j = 0
for i in range(0,n-2):
if Diff[i] == 1 and Diff[i+1] == -1:
pos.append(i+1)
peaks.append(arr[i+1])
if Diff[i] == 1 and Diff[i+1] == 0:
if Diff[i+1:] == [Diff[i+1]]:
break
j = i+1
while(Diff[j] == 0 and j < n-2):
j = j+1
if Diff[j] == -1:
pos.append(i+1)
peaks.append(arr[i+1])
print (pos)
print (peaks)
但是我得到的是所有的峰,我正在尝试解决以单独获得最高峰。
我的数据是:
A=['5662', '5660', '5658', '5658', '5658', '5658', '5655', '5653', '5655', '5660', '5664', '5664', '5662', '5655', '5655', '5655', '5658', '5664', '5674', '5685', '5694', '5699', '5701', '5704', '5706', '5708', '5704', '5701', '5704', '5708', '5713', '5720', '5720', '5724', '5733', '5745', '5761', '5777', '5798', '5819', '5832', '5842', '5846', '5851', '5858', '5862', '5865', '5869', '5874', '5874', '5867', '5855', '5851', '5855', '5865', '5874', '5878', '5883', '5888', '5892', '5897', '5899', '5901', '5901', '5904', '5899', '5894', '5890', '5894', '5899', '5904', '5904', '5894', '5881', '5860', '5839', '5823', '5814', '5809', '5805', '5798', '5791', '5786', '5782', '5779', '5777', '5775', '5773', '5775', '5777', '5779', '5779', '5773', '5763', '5752', '5745', '5740', '5738', '5729', '5717', '5701', '5687', '5678', '5674', '5664', '5653', '5646', '5646', '5651', '5655', '5655', '5653', '5651', '5646', '5646', '5646', '5648', '5653', '5653', '5653', '5653', '5655', '5662', '5664', '5660', '5651', '5648', '5651', '5658', '5662', '5662', '5660', '5658', '5653', '5648', '5648', '5653', '5658', '5658', '5658', '5658', '5662', '5667', '5664', '5658', '5651', '5653', '5655', '5658', '5660', '5662', '5664', '5664', '5660', '5655', '5658', '5664', '5667', '5667', '5664', '5667', '5669', '5669', '5664', '5660', '5658', '5660', '5662', '5664', '5669', '5674', '5674', '5669', '5664', '5662', '5660', '5660', '5658', '5658', '5662', '5669', '5671', '5669', '5662', '5660', '5660', '5664', '5664', '5667', '5667', '5667', '5664', '5660', '5660', '5662', '5664', '5664', '5664', '5667', '5671', '5676', '5674', '5669', '5667', '5664', '5662', '5660', '5662', '5667', '5671', '5674', '5671', '5669', '5669', '5671', '5671', '5669', '5667', '5669', '5674', '5676', '5678', '5676', '5674', '5669', '5669', '5671', '5676', '5678', '5676', '5676', '5676', '5674', '5674', '5669', '5667', '5667', '5669', '5674', '5676', '5676', '5676', '5676', '5671', '5669', '5667', '5667', '5671', '5676', '5676', '5674', '5674', '5676', '5678', '5678', '5674', '5671', '5674', '5678', '5681', '5683', '5683', '5681', '5678', '5674', '5671', '5676', '5681', '5685', '5685', '5683', '5683', '5685', '5683', '5678', '5671', '5671', '5674', '5681', '5683', '5683', '5685', '5694', '5701', '5706', '5706', '5708', '5713', '5720', '5727', '5729', '5733', '5731', '5724', '5717', '5715', '5717', '5724', '5727', '5727', '5727', '5727', '5727', '5724', '5720', '5713', '5713', '5715', '5715', '5713', '5708', '5701', '5694', '5687', '5681', '5676', '5678', '5681', '5681', '5676', '5674', '5676', '5681', '5678', '5674', '5669', '5671', '5676', '5683', '5683', '5685', '5685', '5683', '5678', '5674', '5676', '5681', '5687', '5687', '5683', '5678', '5676', '5681', '5683', '5685', '5685', '5683', '5681', '5681', '5678', '5681', '5678', '5678', '5681', '5690', '5708', '5736', '5766', '5798', '5830', '5871', '5924', '5984', '6044', '6106', '6175', '6262', '6359', '6456', '6543', '6614', '6667', '6688', '6663', '6589', '6488', '6382', '6281', '6175', '6060', '5943', '5839', '5763', '5708', '5660', '5623', '5602', '5602', '5609', '5612', '5612', '5612', '5616', '5625', '5635', '5641', '5648', '5655', '5660', '5664', '5664', '5662', '5662', '5664', '5664', '5667', '5664', '5662', '5662', '5667', '5671', '5676', '5671', '5662', '5658', '5662', '5671', '5676', '5676', '5671', '5669', '5671', '5671', '5671', '5664', '5660', '5660', '5667', '5674', '5681', '5681', '5681', '5681', '5685', '5692', '5697', '5701', '5704', '5708', '5715', '5717', '5715', '5715', '5715', '5713', '5710', '5710', '5717', '5733', '5750', '5761', '5773', '5786', '5805', '5823', '5837', '5846', '5853', '5865', '5876', '5883', '5885', '5885', '5883', '5876', '5869', '5865', '5862', '5871', '5881', '5888', '5894', '5897', '5899', '5901', '5901', '5904', '5906', '5908', '5911', '5911', '5908', '5908', '5908', '5904', '5899', '5897', '5897', '5897', '5888', '5869', '5846', '5828', '5816', '5812', '5805', '5798', '5793', '5796', '5796', '5796', '5796', '5793', '5789', '5786', '5782', '5779', '5779', '5775', '5768', '5759', '5754', '5747', '5738', '5720', '5699', '5685', '5678', '5681', '5681', '5678', '5671', '5667', '5664', '5660', '5658', '5660', '5667', '5671', '5671', '5669', '5669', '5669', '5667', '5664', '5658', '5658', '5662', '5664', '5664', '5664', '5664', '5664', '5662', '5658', '5658', '5660', '5667', '5669', '5667', '5662', '5662', '5664', '5669', '5667', '5660', '5658', '5660', '5667', '5674', '5676', '5676', '5671', '5664', '5658', '5658', '5664', '5671', '5674', '5671', '5669', '5667', '5667', '5664', '5664', '5662', '5662', '5667', '5669', '5676', '5676', '5674', '5671', '5669', '5671', '5674', '5671', '5667', '5667', '5671', '5678', '5681', '5676', '5669', '5667', '5669', '5671', '5674', '5676', '5678', '5681', '5681', '5676', '5671', '5669', '5671', '5674', '5676', '5676', '5681', '5683', '5685', '5685', '5683', '5676', '5671', '5671', '5674', '5681', '5683', '5681', '5678', '5674', '5674', '5674', '5676', '5678', '5678', '5678', '5678', '5681', '5685', '5685', '5681', '5674', '5669', '5671', '5676', '5681', '5683', '5681', '5681', '5678', '5676', '5674', '5676', '5678', '5678', '5678', '5678', '5681', '5683', '5681', '5676', '5669', '5671', '5676', '5681', '5681', '5683', '5683', '5685', '5685', '5683', '5681', '5681', '5683', '5685', '5685', '5683', '5685', '5685', '5683', '5678', '5676', '5681', '5685', '5687', '5685', '5687', '5690', '5690', '5687', '5683', '5678', '5678', '5678', '5681', '5683', '5687', '5692', '5690', '5683', '5674', '5674', '5683', '5694', '5704', '5710', '5715', '5722', '5727', '5729', '5729', '5727', '5727', '5727', '5727', '5729', '5733', '5736', '5736', '5731', '5727', '5727', '5729', '5733', '5731', '5729', '5729', '5733', '5736', '5733', '5724', '5713', '5706', '5701', '5699', '5694', '5692', '5690', '5690', '5687', '5685', '5685', '5685', '5685', '5685', '5685', '5687', '5687', '5690', '5685', '5678', '5669', '5667', '5669', '5678', '5687', '5692', '5694', '5690', '5685', '5683', '5683', '5685', '5683', '5681', '5681', '5683', '5690', '5692', '5692', '5687', '5683', '5676', '5676', '5681', '5692', '5706', '5722', '5745', '5768', '5798', '5828', '5867', '5917', '5977', '6042', '6108', '6187', '6276', '6377', '6469', '6548', '6607', '6658', '6688', '6679', '6617', '6513', '6396', '6285', '6173', '6058', '5940', '5842', '5768', '5717', '5678', '5646', '5621', '5612', '5607', '5605', '5605', '5609', '5623', '5637', '5646', '5653', '5658', '5664', '5667', '5667', '5664', '5660', '5662', '5664', '5671', '5674', '5674', '5671', '5667', '5664', '5667', '5669', '5671', '5674', '5676', '5676', '5676', '5674', '5671', '5674', '5674', '5671', '5667', '5667', '5676', '5683', '5685', '5676', '5669', '5671', '5681', '5685', '5685', '5685', '5692', '5708', '5720', '5722', '5717', '5713', '5717', '5722', '5724', '5724', '5727', '5731', '5731', '5729', '5731', '5743', '5759', '5779', '5791', '5805', '5823', '5844', '5860', '5867', '5862', '5860', '5865', '5876', '5890', '5894', '5892', '5883', '5876', '5874', '5876', '5883', '5892', '5899', '5906', '5908', '5911', '5913', '5915', '5917', '5915', '5908', '5904', '5908', '5917', '5924', '5924', '5915', '5911', '5906', '5901', '5885', '5862', '5839', '5825', '5816', '5812', '5807', '5805', '5802', '5798', '5793', '5791', '5793', '5798', '5800', '5798', '5793', '5791', '5786', '5777', '5768', '5761', '5759', '5754', '5743', '5729', '5717', '5708', '5697', '5681', '5669', '5667', '5671', '5674', '5671', '5671', '5671', '5674', '5671', '5667', '5662', '5664', '5667', '5667', '5664', '5667', '5674', '5678', '5674', '5664', '5660', '5660', '5664', '5667', '5667', '5667', '5669', '5674', '5671', '5667', '5664', '5667', '5671', '5674', '5674', '5674', '5676', '5681', '5676', '5671', '5664', '5667', '5674', '5676', '5674', '5671', '5671', '5678', '5683', '5678', '5667', '5662', '5669', '5678', '5681', '5676', '5674', '5676', '5678', '5674', '5667', '5664', '5669', '5678', '5681', '5676', '5674', '5674', '5678', '5678', '5676', '5671', '5676', '5681', '5683', '5683', '5678', '5676', '5674', '5671', '5669', '5669', '5667', '5669', '5669', '5671', '5676', '5681', '5681', '5678', '5671', '5669', '5671', '5676', '5681', '5685', '5681', '5676', '5671', '5671', '5674', '5681', '5681', '5681', '5678', '5683', '5690', '5692', '5687', '5678', '5669', '5722', '5729', '5733', '5738', '5740', '5738', '5736', '5733', '5736', '5738', '5745', '5747', '5747', '5745', '5740', '5738', '5733', '5733', '5736', '5743', '5750', '5752', '5745', '5736', '5724', '5717', '5713', '5706', '5699', '5694', '5690', '5692', '5694', '5697', '5697', '5692', '5687', '5683', '5683', '5687', '5692', '5694', '5694', '5692', '5690', '5685', '5685', '5685', '5690', '5694', '5697', '5699', '5701', '5701', '5697', '5692', '5685', '5683', '5690', '5694', '5699', '5699', '5699', '5701', '5699', '5692', '5683', '5678', '5685', '5701', '5722', '5745', '5773', '5802', '5832', '5867', '5913', '5968', '6035', '6104', '6177', '6262', '6359', '6458', '6543', '6610', '6658', '6686', '6679', '6624', '6529', '6419', '6313', '6205', '6090', '5968', '5860', '5779', '5727', '5687', '5653', '5625', '5614', '5618', '5623', '5621', '5616', '5618', '5632', '5651', '5662', '5669', '5671', '5671', '5671', '5676', '5678', '5681', '5678', '5674', '5676', '5681', '5687', '5690', '5687', '5683', '5676', '5669', '5669', '5674', '5681', '5687', '5690', '5685', '5681', '5678', '5678', '5678', '5674', '5674', '5676', '5681', '5683', '5683', '5678', '5681', '5683', '5685', '5690', '5701', '5713', '5724', '5729', '5729', '5729', '5727', '5729', '5729', '5729', '5729', '5731', '5733', '5740', '5752', '5761', '5768', '5773', '5784', '5802', '5828', '5848', '5862', '5867', '5871', '5876', '5883', '5888', '5888', '5888', '5885', '5883', '5881', '5878', '5881', '5885', '5894', '5901', '5906', '5911', '5911', '5915', '5917', '5922', '5922', '5920', '5915', '5911', '5911', '5913', '5915', '5920', '5920', '5920', '5911', '5892', '5869', '5848', '5835', '5828', '5823', '5819', '5812', '5807', '5805', '5802', '5802', '5800', '5796', '5791', '5791', '5796', '5800', '5800', '5789', '5773', '5763', '5761', '5763', '5759', '5743', '5724', '5706', '5699', '5697', '5692', '5685', '5676', '5669', '5667', '5669', '5674', '5681', '5685', '5685', '5683', '5678', '5674', '5669', '5669', '5671', '5674', '5674', '5674', '5671', '5671', '5669', '5667', '5667', '5667', '5671', '5678', '5681', '5681', '5678', '5674', '5671', '5667', '5669', '5671', '5676', '5676', '5676', '5676', '5681', '5685', '5683', '5676', '5669', '5669', '5678', '5687', '5690', '5687', '5683', '5678', '5678', '5678', '5683', '5685', '5683', '5681', '5681', '5683', '5687', '5690', '5685', '5678', '5676', '5676', '5678', '5683', '5687', '5687', '5685', '5681', '5676', '5676', '5678', '5681', '5681', '5678', '5681', '5687', '5690', '5685', '5676', '5671', '5674', '5678', '5683', '5683', '5683', '5685', '5687', '5685', '5681', '5676', '5678', '5683', '5685', '5683', '5683', '5687', '5692', '5692', '5687', '5681', '5681', '5685', '5690', '5692', '5690', '5687', '5687', '5687', '5685', '5683', '5681', '5683', '5685', '5687', '5687', '5690', '5690', '5685', '5681', '5678', '5681', '5685', '5687', '5687', '5687', '5690', '5692', '5692', '5690', '5685', '5681', '5681', '5681', '5685', '5690', '5692', '5694', '5690', '5685', '5683', '5685', '5692', '5694', '5694', '5694', '5694', '5697', '5694', '5690', '5685', '5685', '5687', '5690', '5692', '5694', '5697', '5694', '5692', '5687', '5685', '5685', '5687', '5692', '5692', '5692', '5694', '5694', '5694', '5692', '5690', '5687', '5687', '5690', '5694', '5706', '5715', '5720', '5717', '5715', '5717', '5722', '5729', '5733', '5733', '5733', '5738', '5740', '5738', '5733', '5731', '5733', '5736', '5738', '5740', '5743', '5747', '5747', '5743', '5736', '5733', '5738', '5738', '5729', '5717', '5708', '5708', '5713', '5706', '5694', '5685', '5683', '5690', '5697', '5697', '5694', '5690', '5690', '5690', '5690', '5690', '5687', '5690', '5690', '5690', '5692', '5694', '5694', '5692', '5692', '5690', '5687', '5687', '5692', '5697', '5701', '5697', '5692', '5690', '5692', '5697', '5697', '5694', '5694', '5697', '5699', '5699', '5699', '5706', '5722', '5740', '5761', '5786', '5819', '5860', '5911', '5966', '6026', '6088', '6157', '6237', '6331', '6428', '6520', '6596', '6653', '6690', '6688', '6640', '6550', '6440', '6329', '6226', '6118', '6005', '5894', '5805', '5743', '5697', '5658', '5625', '5609', '5607', '5609', '5614', '5621', '5632', '5641', '5646', '5646', '5651', '5662', '5676', '5681', '5678', '5676', '5678', '5683', '5681', '5676', '5671', '5674', '5676', '5678', '5676', '5676', '5678', '5681', '5678', '5674', '5674', '5678', '5683', '5681', '5678', '5678', '5681', '5683', '5681', '5674', '5671', '5676', '5685', '5687', '5690', '5690', '5694', '5701', '5704', '5704', '5708', '5717', '5727', '5729', '5727', '5724', '5729', '5736', '5736', '5729', '5722', '5724', '5736', '5752', '5768', '5784', '5800', '5814', '5828', '5842', '5858', '5869', '5874', '5874', '5874', '5883', '5899', '5908', '5899', '5881', '5865', '5865', '5874', '5888', '5899', '5906', '5908', '5911', '5908', '5906', '5911', '5917', '5922', '5922', '5917', '5917', '5920', '5924', '5922', '5915', '5908', '5906', '5904', '5899', '5885', '5865', '5844', '5830', '5821', '5816', '5807', '5800', '5798', '5802', '5807', '5807', '5802', '5800', '5800', '5800', '5796', '5789', '5779', '5777', '5775', '5773', '5763', '5750', '5738', '5724', '5708', '5694', '5685', '5683', '5685', '5685', '5683', '5681', '5678', '5676', '5674', '5674', '5676', '5683', '5687', '5683', '5676', '5674', '5674', '5676', '5676', '5671', '5669', '5671', '5674', '5678', '5678', '5678', '5674', '5669', '5667', '5669', '5674', '5678', '5678', '5676', '5676', '5678', '5681', '5676', '5667', '5660', '5664', '5674', '5683', '5685', '5681', '5678', '5676', '5674', '5671', '5674', '5676', '5681', '5681', '5681', '5681', '5683', '5683', '5681', '5676', '5676', '5678', '5681', '5681', '5683', '5685', '5685', '5681', '5676', '5676', '5681', '5685', '5685', '5683', '5683', '5685', '5685', '5683', '5678', '5674', '5674', '5678', '5681', '5681', '5678', '5681', '5683', '5685', '5681', '5676', '5676', '5681', '5683', '5685', '5687', '5690', '5690', '5687', '5681', '5676', '5676', '5683', '5687', '5690', '5687', '5685', '5685', '5685', '5683', '5681', '5681', '5683', '5685', '5687', '5685', '5687', '5690', '5690', '5683', '5678', '5678', '5685', '5690', '5692', '5687', '5685', '5690', '5690', '5687', '5683', '5681', '5683', '5687', '5690', '5694', '5694', '5694', '5690', '5685', '5683', '5685', '5690', '5694', '5697', '5694', '5694', '5694', '5692', '5694', '5694', '5692', '5690', '5690', '5694', '5697', '5697', '5694', '5687', '5683', '5681', '5683', '5687', '5687', '5690', '5690', '5690', '5690', '5687', '5687', '5687', '5692', '5694', '5694', '5692', '5690', '5692', '5692', '5690', '5685', '5685', '5692', '5701', '5715', '5722', '5727', '5729', '5731', '5733', '5736', '5731', '5729', '5729', '5731', '5738', '5743', '5740', '5738', '5736', '5738', '5740', '5745', '5745', '5743', '5740', '5743', '5747', '5745', '5736', '5722', '5710', '5704', '5701', '5701', '5701', '5701', '5699', '5697', '5694', '5690', '5692', '5694', '5697', '5697', '5697', '5699', '5699', '5697', '5692', '5687', '5685', '5687', '5692', '5694', '5699', '5701', '5704', '5699', '5694', '5690', '5687', '5690', '5692', '5694', '5701', '5704', '5708', '5706', '5699', '5687', '5678', '5676', '5685', '5701', '5720', '5738', '5759', '5786', '5816', '5851', '5890', '5943', '6003', '6069', '6138', '6219', '6308', '6410', '6502', '6575', '6630', '6674', '6690', '6665', '6589', '6479', '6359', '6249', '6138', '6026', '5915', '5819', '5745', '5692', '5653', '5628', '5618', '5621', '5621', '5614', '5607', '5609', '5628', '5651', '5664', '5667', '5664', '5662', '5667', '5671', '5674', '5669', '5667', '5664', '5671', '5683', '5690', '5687', '5678', '5669', '5664', '5667', '5671', '5676', '5678', '5681', '5678', '5676', '5678', '5678', '5678', '5676', '5676', '5676', '5681', '5681', '5683', '5681', '5678', '5676', '5676', '5683', '5692', '5704', '5710', '5717', '5720', '5724', '5729', '5727', '5722', '5717', '5720', '5724', '5733', '5738', '5740', '5740', '5743', '5752', '5763', '5779', '5800', '5821', '5842', '5853', '5862', '5867', '5871', '5878', '5883', '5888', '5885', '5885', '5885', '5883', '5883', '5881', '5881', '5885', '5897', '5906', '5911', '5911', '5911', '5915', '5922', '5922', '5915', '5911', '5906', '5911', '5913', '5915', '5915', '5917', '5917', '5908', '5894', '5874', '5855', '5844', '5835', '5823', '5816', '5814', '5814', '5809', '5805', '5796', '5793', '5796', '5800', '5802', '5800', '5800', '5798', '5791', '5782', '5770', '5763', '5759', '5752', '5745', '5731', '5720', '5708', '5694', '5683', '5671', '5671', '5671', '5669', '5667', '5667', '5669', '5674', '5674', '5669', '5667', '5669', '5676', '5678', '5676', '5674', '5674', '5681', '5685', '5681', '5671', '5664', '5667', '5674', '5681', '5683', '5683', '5681', '5683', '5683', '5681', '5678', '5678', '5681', '5681', '5681', '5683', '5683', '5683', '5676', '5667', '5664', '5671', '5683', '5687', '5683', '5674', '5671', '5678', '5683', '5683', '5671', '5662', '5662', '5669', '5681', '5687', '5685', '5678', '5674', '5674', '5674', '5678', '5683', '5685', '5685', '5683', '5683', '5681', '5681', '5681', '5676', '5674', '5674', '5678', '5685', '5687', '5683', '5678', '5678', '5681', '5681', '5678', '5674', '5674', '5678', '5685', '5687', '5683', '5678', '5676', '5676', '5678', '5681', '5685', '5687', '5690', '5690', '5687', '5685', '5681', '5678', '5678', '5681', '5683', '5681', '5683', '5685', '5687', '5685', '5681', '5676', '5678', '5685', '5690', '5692', '5692', '5692', '5692', '5685', '5678', '5676', '5681', '5687', '5690', '5687', '5685', '5690', '5694', '5692', '5687', '5681', '5683', '5687', '5692', '5692', '5690', '5685', '5683', '5681', '5681', '5685', '5690', '5690', '5685', '5685', '5690', '5697', '5697', '5687', '5681', '5678', '5685', '5692', '5694', '5694', '5697', '5697', '5694', '5690', '5687', '5690', '5694', '5694', '5692', '5692', '5694', '5701', '5701', '5692', '5681', '5676', '5681', '5687', '5690', '5692', '5692', '5701', '5710', '5717', '5720', '5720', '5724', '5731', '5736', '5738', '5740', '5743', '5745', '5740', '5733', '5729', '5733', '5743', '5745', '5743', '5738', '5738', '5743', '5743', '5738', '5731', '5729', '5731', '5733', '5731', '5727', '5720', '5710', '5701', '5692', '5687', '5690', '5697', '5701', '5699', '5694', '5694', '5694', '5697', '5694', '5690', '5690', '5692', '5699', '5701', '5701', '5697', '5694', '5694', '5694', '5692', '5690', '5692', '5694', '5694', '5690', '5683', '5685', '5692', '5701', '5699', '5694', '5692', '5694', '5699', '5699', '5694', '5694', '5699', '5710', '5727', '5750', '5777', '5809', '5846', '5890', '5940', '5998', '6055', '6118', '6191', '6283', '6384', '6483', '6564', '6626', '6670', '6686', '6663', '6594', '6490', '6380', '6279', '6175', '6062', '5945', '5846', '5770', '5717', '5671', '5635', '5614', '5614', '5623', '5625', '5621', '5618', '5625', '5639', '5651', '5658', '5660', '5664', '5671', '5676', '5676', '5676', '5676', '5676', '5671', '5667', '5667', '5671', '5681', '5685', '5683', '5681', '5678', '5678', '5676', '5674', '5674', '5681', '5685', '5687', '5681', '5676', '5676', '5676', '5676', '5674', '5674', '5678', '5685', '5687', '5687', '5687', '5692', '5701', '5708', '5713', '5715', '5720', '5727', '5733', '5733', '5731', '5727', '5724', '5727', '5729', '5733', '5740', '5747', '5759', '5773', '5784', '5798', '5814', '5830', '5844', '5853', '5858', '5865', '5876', '5890', '5901', '5899', '5888', '5876', '5869', '5869', '5874', '5881', '5888', '5897', '5904', '5906', '5908', '5908', '5911', '5913', '5917', '5917', '5920', '5922', '5924', '5922', '5915', '5911', '5911', '5915', '5915', '5904', '5885', '5867', '5853', '5839', '5828', '5814', '5807', '5805', '5807', '5809', '5807', '5807', '5809', '5807', '5798', '5789', '5786', '5791', '5791', '5786', '5775', '5766', '5761', '5761', '5750', '5733', '5715', '5704', '5697', '5694', '5687', '5683', '5676', '5671', '5667', '5664', '5664', '5667', '5671', '5674', '5676', '5676', '5681', '5678', '5676', '5671', '5671', '5674', '5678', '5678', '5678', '5676', '5678', '5676', '5674', '5669', '5669', '5669', '5671', '5671', '5674', '5676', '5678', '5676', '5669', '5662', '5662', '5669', '5678', '5681', '5676', '5676', '5674', '5674', '5674', '5674', '5674', '5676', '5674', '5674', '5676', '5685', '5690', '5685', '5676', '5669', '5669', '5676', '5681', '5681', '5678', '5678', '5678', '5676', '5674', '5671', '5671', '5674', '5678', '5683', '5683', '5683', '5683', '5681', '5678', '5676', '5676', '5676', '5681', '5683', '5685', '5687', '5687', '5687', '5685', '5685', '5685', '5685', '5685', '5685', '5687', '5690', '5690', '5690', '5683', '5678', '5676', '5685', '5694', '5697', '5690', '5683', '5681', '5687', '5692', '5685', '5678', '5676', '5678', '5687', '5690', '5690', '5690', '5685', '5681', '5676', '5676', '5683', '5687', '5690', '5687', '5687', '5692', '5692', '5690', '5683', '5681', '5683', '5690', '5692', '5692', '5692', '5692', '5690', '5687', '5683', '5683', '5685', '5690', '5692', '5694', '5699', '5699', '5697', '5690', '5685', '5685', '5687', '5687', '5685', '5683', '5685', '5690', '5690', '5687', '5685', '5687', '5692', '5692', '5692', '5692', '5694', '5697', '5694', '5690', '5683', '5683', '5685', '5690', '5697', '5697', '5694', '5687', '5681', '5681', '5685', '5692', '5701', '5706', '5713', '5722', '5733', '5738', '5740', '5738', '5733', '5733', '5736', '5740', '5743', '5745', '5740', '5738', '5736', '5733', '5736', '5740', '5740', '5740', '5738', '5738', '5743', '5745', '5743', '5733', '5720', '5713', '5710', '5708', '5704', '5697', '5692', '5692', '5692', '5690', '5687', '5687', '5690', '5692', '5694', '5697', '5699', '5701', '5699', '5694', '5690', '5690', '5690', '5694', '5699', '5701', '5701', '5699', '5692', '5687', '5685', '5685', '5685', '5687', '5692', '5701', '5706', '5704', '5692', '5683', '5683', '5687', '5692', '5690', '5694', '5706', '5727', '5752', '5777', '5800', '5830', '5869', '5920', '5980', '6046', '6115', '6191', '6274', '6366', '6458', '6543', '6614', '6667', '6695', '6683', '6621', '6525', '6414', '6306', '6200', '6085', '5963', '5855', '5775', '5727', '5687', '5651', '5623', '5614', '5616', '5618', '5616', '5616', '5628', '5646', '5662', '5669', '5669', '5671', '5674', '5674', '5669', '5669', '5674', '5681', '5685', '5681', '5676', '5671', '5671', '5674', '5676', '5678', '5681', '5681', '5681', '5683', '5685', '5687', '5683', '5674', '5669', '5671', '5678', '5685', '5685', '5683', '5678', '5681', '5685', '5687', '5687', '5687', '5687', '5694', '5704', '5713', '5722', '5727', '5727', '5722', '5722', '5722', '5727', '5731', '5733', '5736', '5736', '5736', '5738', '5747', '5759', '5775', '5796', '5814', '5830', '5846', '5858', '5865', '5867', '5867', '5871', '5883', '5894', '5899', '5892', '5881', '5874', '5874', '5885', '5892', '5899', '5904', '5908', '5913', '5917', '5922', '5927', '5924', '5920', '5913', '5911', '5913', '5922', '5927', '5924', '5920', '5917', '5913', '5901', '5885', '5867', '5853', '5842', '5832', '5825', '5819', '5812', '5802', '5798', '5798', '5798', '5800', '5798', '5793', '5793', '5798', '5802', '5798', '5782', '5768', '5761', '5763', '5763', '5756', '5743', '5727', '5715', '5704', '5692', '5681', '5676', '5676', '5681', '5678', '5674', '5669', '5669', '5671', '5669', '5664', '5662', '5667', '5671', '5676', '5676', '5676', '5676', '5676', '5671', '5669', '5667', '5671', '5678', '5683', '5681', '5678', '5678', '5676', '5674', '5671', '5669', '5671', '5674', '5674', '5674', '5674', '5674', '5674', '5671', '5674', '5678', '5681', '5678', '5674', '5676', '5681', '5687', '5687', '5678', '5671', '5669', '5674', '5674', '5676', '5678', '5683', '5683', '5676', '5667', '5667', '5674', '5683', '5685', '5678', '5676', '5678', '5683', '5683', '5676', '5671', '5671', '5676', '5683', '5687', '5690', '5687', '5685', '5681', '5676', '5676', '5678', '5678', '5678', '5681', '5685', '5690', '5690', '5683', '5678', '5674', '5676', '5683', '5687', '5692', '5692', '5690', '5687', '5683', '5681', '5681', '5683', '5683', '5683', '5683', '5685', '5687', '5687', '5683', '5676', '5676', '5678', '5685', '5690', '5690', '5690', '5687', '5685', '5683', '5683', '5685', '5685', '5690', '5690', '5690', '5692', '5694', '5694', '5694', '5690', '5685', '5685', '5687', '5690', '5692', '5690', '5685', '5683', '5683', '5683', '5685', '5685', '5685', '5687', '5692', '5694', '5697', '5699', '5697', '5692', '5687', '5687', '5692', '5697', '5699', '5697', '5692', '5692', '5697', '5697', '5692', '5685', '5683', '5690', '5699', '5706', '5704', '5697', '5690', '5685', '5683', '5685', '5690', '5694', '5694', '5692', '5692', '5697', '5706', '5710', , '5860', '5862', '5865', '5869', '5878', '5888', '5892', '5892', '5890', '5883', '5878', '5874', '5876', '5883', '5890', '5899']
请帮忙。
首先,将您的字符串列表转换为 numpy 数组 或 pandas 系列:
import pandas as pd
s = pd.Series(A).astype(int)
其次,找出所有的极值(例如分布的极值1%),最后通过连续的值(峰值)得到最大值。我们可以很容易地识别连续的组 more_itertools.consecutive_groups
:
from more_itertools import consecutive_groups
grp_peaks = consecutive_groups(s[s >= s.quantile(.99)].index)
max_peaks = [s[grp].idxmax() for grp in grp_peaks]
print(s[max_peaks])
输出:
372 6688
787 6688
1132 6686
1547 6690
1963 6690
2378 6686
2793 6695
dtype: int64
数据可视化:
import matplotlib.pyplot as plt
plt.figure(figsize=(12,8))
plt.plot(s, marker='o')
# Set a line delimiting the extreme 1% values of the distribution
plt.axhline(y=s.quantile(.99), color='r', linestyle='--')
# Identify the maximum value per peak
plt.plot(s[max_peaks], color='r', marker='o', linestyle='None')
plt.show()
无需导入任何库即可重现上述结果的方法:
# Convert list of strings to integers and get respective indexes
A = list(map(int, A))
idx = range(len(A))
# Calculate empirical p-values to get the peaks
pval = [1 - sum([i >= j for j in A]) / (len(A)+1) for i in A]
# Identify extreme values (peaks)
stat_pval = [idx for idx,p in enumerate(pval) if p <= 0.01]
# Identify consecutive indexes in target
grps = []
consec_idx = []
stat_pval.append(stat_pval[-1]+2)
for i in range(len(stat_pval)-1):
if stat_pval[i] == stat_pval[i+1]-1:
consec_idx.append(stat_pval[i])
else:
consec_idx.append(stat_pval[i])
grps.append(consec_idx)
consec_idx = []
del consec_idx
del stat_pval[-1]
# Then, identify the maximum value per peak:
[max(A[grp[0]:grp[-1]+1]) for grp in grps]
[6688, 6688, 6686, 6690, 6690, 6686, 6695]
或者,如果您想打印每个峰的最大值及其索引:
idx_and_max_per_peak = []
for grp in grps:
peak = A[grp[0]:grp[-1]+1]
peak_max = max(peak)
idx_and_max_per_peak.extend([(grp[i], value) for i,value in enumerate(peak) if value==peak_max])
idx_and_max_per_peak
的输出:
[(372, 6688),
(787, 6688),
(1132, 6686),
(1547, 6690),
(1963, 6690),
(2378, 6686),
(2793, 6695)]