识别最高峰值,并通过保持最高峰值作为参考,返回最高峰值左右两侧较低的值

2022-07-06 11:19:26 发布

您现在位置:Python中文网/ 问答频道 /正文

我有数据,我需要通过保持最高值或峰值作为参考来返回较低的值,有许多峰值,我需要返回每个峰值的低点,并将它们存储到变量中

样本数据:

A=['6452', '6444', '6452', '6456', '6455', '6465', '6456', '6442', '6449', '6452', '6455', '6465', '6463', '6452', '6459', '6470', '6456', '6435', '6438', '6441', '6438', '6448', '6451', '6439', '6449', '6472', '6483', '6503', '6531', '6524', '6523', '6538', '6550', '6534', '6537', '6554', '6540', '6538', '6553', '6558', '6568', '6588', '6609', '6615', '6616', '6625', '6628', '6633', '6628', '6612', '6605', '6605', '6599', '6587', '6588', '6589', '6584', '6592', '6592', '6571', '6555', '6551', '6533', '6521', '6517', '6502', '6493', '6476', '6473', '6469', '6455', '6463', '6462', '6438', '6424', '6428', '6417', '6400', '6404', '6398', '6398', '6417', '6425', '6422', '6429', '6448', '6435', '6424', '6434', '6439', '6431', '6429', '6418', '6407', '6412', '6415', '6407', '6412', '6424', '6415', '6403', '6417', '6425', '6424', '6425', '6428', '6427', '6432', '6455', '6442', '6420', '6446', '6503', '6558', '6654', '6748', '6841', '6945', '7053', '7160', '7229', '7237', '7150', '7062', '7025', '6882', '6657', '6493', '6391', '6278', '6156', '6083', '6076', '6081', '6091', '6115', '6145', '6189', '6234', '6282', '6298', '6323', '6370', '6393', '6408', '6429', '6427', '6431', '6452', '6454', '6456', '6465', '6461', '6456', '6472', '6487', '6493', '6493', '6509', '6500', '6496', '6497', '6487', '6472', '6480', '6496', '6489', '6490', '6506', '6506', '6492', '6507', '6517', '6507', '6485', '6495', '6496', '6500', '6509', '6502', '6492', '6510', '6530', '6533', '6545', '6545', '6530', '6526', '6533', '6536', '6527', '6533', '6531', '6527', '6529', '6536', '6538', '6554', '6561', '6555', '6553', '6567', '6574', '6570', '6572', '6581', '6578', '6582', '6608', '6613', '6616', '6625', '6643', '6643', '6652', '6662', '6662', '6653', '6670', '6684', '6686', '6700', '6714', '6714', '6737', '6759', '6761', '6768', '6778', '6786', '6785', '6785', '6792', '6786', '6779', '6790', '6807', '6813', '6823', '6819', '6812', '6826', '6828', '6830', '6833', '6836', '6816', '6799', '6806', '6821', '6813', '6793', '6800', '6793', '6796', '6807', '6787', '6770', '6773', '6753', '6737', '6728', '6722', '6703', '6686', '6670', '6639', '6618', '6618', '6609', '6594', '6585', '6571', '6547', '6543', '6543', '6543', '6514', '6512', '6523', '6514', '6492', '6485', '6482', '6487', '6482', '6473', '6492', '6506', '6489', '6473', '6476', '6478', '6475', '6480', '6483', '6461', '6452', '6465', '6463', '6463', '6463', '6466', '6461', '6459', '6473', '6463', '6454', '6462', '6462', '6445', '6449', '6469', '6470', '6475', '6473', '6469', '6475', '6486', '6483', '6486', '6497', '6499', '6495', '6502', '6495', '6487', '6483', '6490', '6493', '6486', '6497', '6489', '6473', '6483', '6514', '6510', '6497', '6503', '6510', '6521', '6503', '6496', '6489', '6490', '6497', '6492', '6485', '6495', '6490', '6490', '6497', '6504', '6493', '6487', '6506', '6507', '6496', '6499', '6497', '6492', '6506', '6502', '6493', '6502', '6510', '6506', '6502', '6512', '6519', '6502', '6504', '6526', '6507', '6504', '6517', '6519', '6506', '6513', '6514', '6502', '6509', '6516', '6503', '6506', '6516', '6514', '6500', '6503', '6513', '6521', '6524', '6526', '6509', '6523', '6530', '6524', '6524', '6534', '6524', '6517', '6536', '6544', '6540', '6529', '6547', '6553', '6536', '6543', '6540', '6527', '6540', '6540', '6526', '6529', '6533', '6537', '6523', '6533', '6541', '6531', '6540', '6550', '6543', '6537', '6548', '6548', '6548', '6564', '6561', '6560', '6557', '6553', '6547', '6548', '6553', '6554', '6554', '6555', '6558', '6551', '6557', '6574', '6565', '6561', '6564', '6558', '6551', '6550', '6554', '6554', '6547', '6555', '6544', '6555', '6562', '6548', '6545', '6558', '6554', '6545', '6545', '6545', '6541', '6560', '6579', '6575', '6577', '6587', '6589', '6599', '6628', '6636', '6623', '6623', '6628', '6623', '6628', '6646', '6654', '6653', '6660', '6667', '6669', '6676', '6680', '6677', '6679', '6684', '6676', '6664', '6656', '6657', '6646', '6659', '6669', '6663', '6645', '6640', '6625', '6606', '6606', '6599', '6572', '6553', '6545', '6543', '6533', '6533', '6534', '6516', '6516', '6541', '6521', '6492', '6493', '6490', '6482', '6479', '6478', '6489', '6483', '6487', '6495', '6500', '6507', '6510', '6493', '6495', '6495', '6482', '6476', '6485', '6478', '6480', '6500', '6499', '6478', '6500', '6510', '6513', '6512', '6521', '6504', '6492', '6495', '6503', '6493', '6509', '6495', '6475', '6485', '6529', '6577', '6664', '6759', '6845', '6950', '7062', '7171', '7264', '7288', '7215', '7128', '7114', '7032', '6814', '6618', '6512', '6410', '6278', '6190', '6183', '6183', '6180', '6186', '6212', '6236', '6294', '6340', '6354', '6387', '6434', '6456', '6492', '6509', '6509', '6516', '6540', '6560', '6567', '6560', '6553', '6541', '6564', '6582', '6577', '6568', '6579', '6591', '6574', '6558', '6561', '6551', '6541', '6547', '6554', '6558', '6574', '6575', '6577', '6578', '6594', '6589', '6594', '6601', '6596', '6579', '6601', '6606', '6599', '6611', '6635', '6625', '6611', '6623', '6635', '6622', '6632', '6628', '6601', '6605', '6622', '6623', '6628', '6628', '6632', '6636', '6649', '6652', '6654', '6656', '6663', '6654', '6652', '6653', '6646', '6652', '6671', '6679', '6684', '6703', '6704', '6712', '6720', '6746', '6770', '6749', '6752', '6753', '6744', '6746', '6775', '6783', '6787', '6803', '6817', '6826', '6834', '6844', '6843', '6853', '6874', '6867', '6860', '6847', '6853', '6861', '6872', '6875', '6878', '6874', '6889', '6878', '6875', '6879', '6888', '6885', '6895', '6894', '6881', '6878', '6891', '6877', '6860', '6854', '6840', '6824', '6820', '6812', '6793', '6763', '6758', '6748', '6742', '6738', '6720', '6669', '6649', '6646', '6632', '6619', '6619', '6608', '6588', '6567', '6577', '6574', '6564', '6561', '6554', '6536', '6534', '6519', '6517', '6526', '6510', '6497', '6516', '6521', '6516', '6513', '6514', '6497', '6504', '6531', '6533', '6516', '6510', '6523', '6521', '6504', '6495', '6487', '6499', '6504', '6480', '6475', '6493', '6503', '6490', '6487', '6487', '6493', '6495', '6512', '6503', '6476', '6482', '6496', '6502', '6502', '6504', '6500', '6503', '6496', '6506', '6487', '6490', '6500', '6486', '6486', '6510', '6509', '6499', '6504', '6510', '6490', '6495', '6504', '6504', '6500', '6507', '6506', '6497', '6503', '6512', '6495', '6514', '6533', '6517', '6502', '6509', '6493', '6496', '6509', '6504', '6500', '6519', '6510', '6482', '6468', '6472', '6465', '6459', '6473', '6479', '6452', '6456', '6463', '6462', '6472', '6478', '6485', '6476', '6492', '6497', '6478', '6475', '6493', '6490', '6495', '6507', '6507', '6503', '6492', '6469', '6452', '6451', '6465', '6472', '6456', '6448', '6441', '6438', '6462', '6476', '6459', '6472', '6493', '6480', '6473', '6478', '6469', '6463', '6465', '6469', '6466', '6456', '6449', '6451', '6434', '6438', '6451', '6444', '6449', '6449', '6437', '6442', '6452', '6439', '6442', '6445', '6429', '6425', '6431', '6437', '6432', '6418', '6421', '6422', '6418', '6428', '6445', '6439', '6441', '6441', '6427', '6432', '6441', '6444', '6441', '6438', '6422', '6418', '6415', '6418', '6404', '6415', '6434', '6429', '6414', '6405', '6403', '6407', '6421', '6431', '6415', '6429', '6432', '6428', '6446', '6469', '6469', '6466', '6489', '6497', '6479', '6497', '6500', '6483', '6489', '6489', '6513', '6530', '6536', '6530', '6530', '6541', '6531', '6537', '6544', '6543', '6547', '6541', '6540', '6533', '6520', '6547', '6577', '6574', '6557', '6533', '6520', '6521', '6502', '6476', '6441', '6425', '6414', '6393', '6374', '6364', '6349', '6352', '6360', '6356', '6343', '6357', '6362', '6343', '6349', '6369', '6337', '6333', '6346', '6350', '6345', '6356', '6349', '6321', '6309', '6336', '6325', '6319', '6332', '6336', '6335', '6340', '6340', '6349', '6369', '6376', '6356', '6339', '6337', '6340', '6328', '6318', '6313', '6308', '6304', '6326', '6308', '6289', '6304', '6340', '6369', '6410', '6495', '6582', '6666', '6770', '6881', '6981', '7059', '7024', '6920', '6913', '6919', '6756', '6550', '6437', '6340', '6237', '6146', '6105', '6087', '6079', '6079', '6071', '6091', '6161', '6190', '6197', '6221', '6246', '6284', '6339', '6367', '6377', '6388', '6408', '6412', '6418', '6432', '6444', '6424', '6429', '6459', '6441', '6452', '6463', '6452', '6461', '6485', '6499', '6473', '6455', '6462', '6485', '6493', '6496', '6492', '6473', '6480', '6496', '6479', '6476', '6482', '6468', '6472', '6489', '6502', '6493', '6514', '6533', '6534', '6543', '6547', '6547', '6553', '6557', '6536', '6516', '6523', '6513', '6500', '6527', '6558', '6544', '6550', '6554', '6568', '6579', '6604', '6594', '6560', '6571', '6579', '6555', '6537', '6553', '6571', '6578', '6578', '6587', '6582', '6599', '6622', '6622', '6611', '6619', '6637', '6640', '6646', '6662', '6662', '6681', '6698', '6704', '6704', '6728', '6725', '6718', '6717', '6729', '6738', '6745', '6734', '6742', '6745', '6755', '6761', '6763', '6772', '6770', '6768', '6768', '6758', '6755', '6759', '6766', '6758', '6756', '6755', '6751', '6749', '6739', '6732', '6745', '6737', '6729', '6708', '6697', '6695', '6686', '6670', '6653', '6646', '6637', '6623', '6601', '6584', '6567', '6575', '6558', '6530', '6524', '6533', '6513', '6486', '6470', '6468', '6442', '6439', '6446', '6427', '6418', '6415', '6397', '6414', '6427', '6428', '6417', '6424', '6438', '6435', '6438', '6449', '6438', '6434', '6444', '6448', '6431', '6425', '6424', '6421', '6429', '6439', '6429', '6432', '6444', '6449', '6442', '6448', '6456', '6439', '6431', '6432', '6421', '6431', '6432', '6427', '6455', '6456', '6455', '6444', '6452', '6455', '6445', '6452', '6458', '6448', '6428', '6415', '6434', '6432', '6432', '6449', '6435', '6435', '6434', '6425', '6414', '6432', '6445', '6445', '6448', '6438', '6434', '6435', '6448', '6439', '6428', '6448', '6445', '6429', '6432', '6434', '6429', '6435', '6446', '6444', '6424', '6427', '6431', '6429', '6420', '6418', '6417', '6425', '6431', '6431', '6421', '6424', '6441', '6437', '6444', '6442', '6442', '6432', '6446', '6445', '6438', '6461', '6472', '6451', '6437', '6448', '6459', '6459', '6465', '6456', '6441', '6437', '6452', '6441', '6445', '6445', '6435', '6437', '6463', '6485', '6465', '6454', '6469', '6475', '6465', '6478', '6466', '6461', '6463', '6449', '6442', '6451', '6455', '6458', '6461', '6462', '6465', '6461', '6470', '6479', '6468', '6470', '6476', '6475', '6470', '6473', '6475', '6452', '6444', '6452', '6438', '6446', '6448', '6439', '6435', '6456', '6463', '6458', '6461', '6459', '6463', '6472', '6472', '6466', '6461', '6468', '6469', '6466', '6480', '6504', '6521', '6519', '6524', '6533', '6545', '6570', '6570', '6555', '6558', '6558', '6570', '6565', '6562', '6565', '6567', '6581', '6589', '6591', '6608', '6606', '6602', '6605', '6616', '6620', '6623', '6625', '6622', '6601', '6599', '6620', '6622', '6616', '6584', '6565', '6557', '6555', '6529', '6496', '6496', '6485', '6478', '6470', '6452', '6446', '6448', '6446', '6425', '6412', '6405', '6408', '6390', '6384', '6376', '6363', '6370', '6398', '6410', '6420', '6427', '6422', '6410', '6400', '6405', '6400', '6404', '6407', '6398', '6379', '6383', '6390', '6393', '6412', '6412', '6415', '6410', '6424', '6429', '6415', '6404', '6411', '6417', '6424', '6417', '6394', '6388', '6408', '6448', '6517', '6613', '6705', '6790', '6916', '7036', '7140', '7215', '7198', '7095', '7042', '7024', '6881', '6645', '6509', '6410', '6279', '6168', '6132', '6129', '6121', '6121', '6129', '6162', '6209', '6250', '6274', '6295', '6339', '6373', '6398', '6425', '6452', '6444', '6463', '6490', '6495', '6495', '6499', '6500', '6486', '6502', '6517', '6510', '6526', '6531', '6520', '6512', '6512', '6520', '6519', '6519', '6523', '6514', '6533', '6550', '6547', '6547', '6550', '6545', '6541', '6541', '6544', '6538', '6538', '6544', '6545', '6561', '6584', '6588', '6582', '6599', '6609', '6591', '6594', '6606', '6592', '6579', '6588', '6596', '6598', '6611', '6623', '6622', '6633', '6652', '6656', '6646', '6664', '6670', '6642', '6652', '6663', '6660', '6669', '6677', '6677', '6690', '6715', '6711', '6714', '6735', '6751', '6745', '6746', '6763', '6766', '6768', '6782', '6799', '6797', '6804', '6826', '6838', '6848', '6854', '6861', '6872', '6888', '6884', '6878', '6895', '6918', '6908', '6913', '6918', '6925', '6933', '6926', '6913', '6930', '6929', '6918', '6901', '6896', '6891', '6885', '6879', '6887', '6881', '6872', '6872', '6872', '6847', '6836', '6845', '6828', '6813', '6797', '6778', '6755', '6732', '6721', '6704', '6695', '6687', '6653', '6639', '6642', '6629', '6613', '6612', '6615', '6596', '6584', '6585', '6574', '6561', '6564', '6560', '6545', '6540', '6543', '6533', '6529', '6537', '6521', '6507', '6519', '6517', '6506', '6507', '6510', '6500', '6497', '6507', '6514', '6514', '6523', '6519', '6507', '6509', '6521', '6506', '6507', '6519', '6504', '6492', '6510', '6507', '6507', '6514', '6521', '6520', '6530', '6540', '6524', '6514', '6534', '6531', '6499', '6504', '6513', '6509', '6510', '6502', '6497', '6489', '6504', '6516', '6517', '6504', '6509', '6493', '6492', '6502', '6496', '6496', '6512', '6490', '6479', '6486', '6499', '6495', '6495', '6499', '6495', '6482', '6489', '6487', '6496', '6503', '6496', '6478', '6480', '6483', '6476', '6469', '6472', '6469', '6461', '6461', '6463', '6456', '6461', '6463', '6462', '6452', '6461', '6468', '6458', '6441', '6442', '6445', '6451', '6461', '6452', '6446', '6446', '6448', '6441', '6445', '6459', '6442', '6431', '6439', '6434', '6439', '6446', '6437', '6428', '6438', '6449', '6439', '6435', '6445', '6437', '6429', '6445', '6448', '6442', '6444', '6454', '6432', '6424', '6445', '6442', '6415', '6420', '6411', '6410', '6418', '6427', '6417', '6424', '6434', '6429', '6424', '6434', '6441', '6429', '6429', '6435', '6424', '6417', '6434', '6435', '6418', '6445', '6449', '6441', '6444', '6442', '6424', '6424', '6432', '6424', '6414', '6408', '6417', '6415', '6410', '6435', '6432', '6454', '6466', '6472', '6476', '6500', '6510', '6507', '6510', '6516', '6510', '6512', '6523', '6531', '6523', '6540', '6547', '6554', '6562', '6574', '6567', '6562', '6584', '6589', '6570', '6560', '6550', '6548', '6544', '6564', '6562', '6558', '6553', '6533', '6510', '6513', '6510', '6483', '6458', '6459', '6445', '6428', '6418', '6425', '6422', '6427', '6434', '6417', '6408', '6405', '6387', '6366', '6369', '6360', '6342', '6360', '6369', '6364', '6364', '6387', '6379', '6369', '6377', '6383', '6383', '6371', '6360', '6354', '6362', '6369', '6360', '6370', '6377', '6373', '6364', '6379', '6387', '6381', '6377', '6371', '6376', '6403', '6414', '6405', '6383', '6381', '6418', '6468', '6538', '6646', '6722', '6827', '6939', '7041', '7145', '7233', '7242', '7113', '7027', '6997', '6830', '6596', '6444', '6332', '6196', '6088', '6032', '6018', '6033', '6052', '6067', '6108', '6179', '6219', '6224', '6267', '6318', '6352', '6370', '6388', '6393', '6403', '6421', '6425', '6437', '6451', '6461', '6455', '6445', '6459', '6466', '6482', '6499', '6497', '6485', '6480', '6479', '6468', '6473', '6487', '6478', '6490', '6507', '6506', '6502', '6513', '6514', '6514', '6507', '6502', '6497', '6497', '6499', '6495', '6492', '6513', '6527', '6523', '6534', '6541', '6537', '6548', '6554', '6536', '6510', '6517', '6534', '6533', '6506', '6517', '6523', '6541', '6543', '6553', '6560', '6574', '6572', '6570', '6577', '6581', '6571', '6572', '6587', '6581', '6572', '6594', '6615', '6616', '6609', '6626', '6632', '6639', '6659', '6667', '6647', '6654', '6681', '6681', '6688', '6703', '6701', '6710', '6722', '6727', '6734', '6746', '6753', '6753', '6761', '6769', '6773', '6770', '6768', '6769', '6775', '6783', '6775', '6761', '6756', '6768', '6751', '6755', '6761', '6761', '6741', '6739', '6739', '6731', '6729', '6735', '6722', '6704', '6704', '6701', '6691', '6684', '6659', '6640', '6637', '6633', '6599', '6575', '6557', '6543', '6527', '6516', '6504', '6486', '6478', '6480', '6473', '6456', '6458', '6452', '6438', '6444', '6434', '6400', '6391', '6404', '6391', '6379', '6370', '6363', '6364', '6373', '6370', '6364', '6362', '6370', '6371', '6370', '6384', '6379', '6357', '6364', '6381', '6369', '6356', '6369', '6369', '6366', '6367', '6360', '6362', '6386', '6393', '6381', '6371', '6377', '6379', '6377', '6383', '6373', '6357', '6364', '6376', '6380', '6362', '6377', '6383', '6388', '6400', '6401', '6373', '6383', '6407', '6404', '6400', '6400', '6383', '6398', '6407', '6410', '6394', '6397', '6408', '6407', '6401', '6394', '6390', '6401', '6414', '6404', '6393', '6408', '6420', '6408', '6407', '6407', '6398', '6407', '6408', '6405', '6394', '6401', '6405', '6404', '6400', '6410', '6405', '6401', '6408', '6414', '6397', '6397', '6396', '6398', '6400', '6408', '6410', '6407', '6412', '6424', '6421', '6422', '6411', '6414', '6412', '6420', '6407', '6408', '6412', '6412', '6401', '6407', '6412', '6417', '6420', '6424', '6410', '6417', '6422', '6410', '6393', '6412', '6425', '6407', '6403', '6412', '6408', '6405', '6407', '6414', '6410', '6420', '6429', '6415', '6410', '6412', '6408', '6412', '6421', '6410', '6408', '6418', '6412', '6401', '6398', '6410', '6405', '6398', '6411', '6412', '6401', '6407', '6412', '6412', '6417', '6425', '6412', '6418', '6428', '6429', '6412', '6417', '6420', '6420', '6425', '6427', '6418', '6414', '6415', '6415', '6412', '6421', '6424', '6417', '6420', '6449', '6466', '6469', '6478', '6500', '6506', '6523', '6536', '6531', '6541', '6554', '6545', '6533', '6537', '6534', '6538', '6558', '6572', '6562', '6572', '6585', '6578', '6582', '6595', '6615', '6604', '6602', '6596', '6589', '6585', '6595', '6608', '6612', '6605', '6589', '6571', '6575', '6558', '6541', '6529', '6519', '6504', '6499', '6495', '6495', '6480', '6482', '6483', '6478', '6485', '6485', '6452', '6437', '6439', '6435', '6431', '6444', '6458', '6465', '6469', '6479', '6482', '6476', '6489', '6496', '6475', '6470', '6475', '6472', '6478', '6478', '6469', '6475', '6492', '6516', '6503', '6510', '6523', '6514', '6513', '6516', '6503', '6512', '6537', '6538', '6513', '6502', '6512', '6555', '6612', '6711', '6802', '6885', '7003', '7107', '7205', '7308', '7368', '7303', '7178', '7136', '7070', '6862', '6663', '6540', '6415', '6288', '6203', '6176', '6189', '6210', '6214', '6238', '6287', '6333', '6371', '6414', '6459', '6485', '6506', '6521', '6526', '6553', '6570', '6577', '6585', '6588', '6588', '6591', '6591', '6609', '6616', '6620', '6629', '6636', '6622', '6625', '6611', '6598', '6587', '6594', '6592', '6599', '6596', '6606', '6613', '6630', '6647', '6640', '6646', '6652', '6629', '6616', '6625', '6625', '6622', '6640', '6643', '6650', '6639', '6647', '6660', '6669', '6669', '6666', '6646', '6637', '6650', '6636', '6639', '6662', '6654', '6656', '6677', '6694', '6688', '6701', '6714', '6712', '6708', '6722', '6722', '6722', '6728', '6729', '6731', '6744', '6749', '6755', '6765', '6792', '6795', '6778', '6790', '6807', '6809', '6799', '6814', '6824', '6819', '6830', '6850', '6864', '6872', '6891', '6887', '6902', '6929', '6928', '6923', '6929', '6939', '6937', '6937', '6940', '6939', '6959', '6966', '6959', '6957', '6963', '6952', '6953', '6970', '6980', '6969', '6956', '6969', '6969', '6973', '6974', '6970', '6962', '6947', '6936', '6911', '6887', '6882', '6870', '6847', '6840', '6820', '6799', '6790', '6792', '6779', '6769', '6753', '6738', '6722', '6712', '6701', '6691', '6681', '6683', '6671', '6666', '6660', '6643', '6652', '6652', '6640', '6622', '6613', '6623', '6623', '6620', '6609', '6618', '6620', '6623', '6628', '6618', '6620', '6625', '6619', '6616', '6626', '6633', '6632', '6635', '6633', '6636', '6650', '6663', '6653', '6647', '6643', '6639', '6646', '6654', '6662', '6652', '6656', '6667', '6660', '6663', '6673', '6660', '6652', '6663', '6662', '6642', '6640', '6650', '6645', '6653', '6676', '6673', '6657', '6667', '6670', '6676', '6686', '6679', '6653', '6656', '6664', '6650', '6652', '6656', '6650', '6643', '6645', '6649', '6646', '6649', '6653', '6645', '6662', '6662', '6650', '6643', '6649', '6653', '6657', '6662', '6664', '6654', '6652', '6650', '6659', '6659', '6662', '6666', '6662', '6659', '6656', '6654', '6646', '6663', '6659', '6649', '6652', '6652', '6647', '6636', '6646', '6649', '6642', '6643', '6647', '6636', '6636', '6632', '6629', '6629', '6646', '6632', '6622', '6620', '6625', '6628', '6629', '6637', '6633', '6635', '6637', '6633', '6640', '6637', '6636', '6646', '6637', '6625', '6620', '6626', '6628', '6629', '6619', '6630', '6642', '6639', '6637', '6645', '6628', '6625', '6645', '6643', '6632', '6626', '6625', '6622', '6633', '6635', '6623', '6626', '6632', '6629', '6626', '6632', '6637', '6622', '6633', '6642', '6640', '6647', '6654', '6652', '6635', '6646', '6656', '6646', '6649', '6652', '6640', '6630', '6647', '6662', '6669', '6659', '6652', '6667', '6686', '6704', '6722', '6720', '6720', '6738', '6748', '6762', '6759', '6746', '6755', '6761', '6758', '6766', '6780', '6792', '6793', '6806', '6820', '6816', '6830', '6837', '6821', '6816', '6804', '6802', '6800', '6804', '6796', '6790', '6786', '6785', '6779', '6769', '6758', '6732', '6717', '6714', '6693', '6666', '6660', '6676', '6653', '6649', '6664', '6666', '6663', '6657', '6653', '6636', '6636', '6642', '6625', '6608', '6616', '6615', '6623', '6633', '6646', '6649', '6649', '6650', '6643', '6642', '6649', '6639', '6630', '6633', '6630', '6640', '6654', '6660', '6657', '6656', '6663', '6676', '6674', '6671', '6669', '6650', '6650', '6659', '6663', '6669', '6663', '6659', '6680', '6746', '6819', '6901', '6988', '7097', '7198', '7295', '7416', '7469', '7438', '7338', '7261', '7218', '7073', '6855', '6700', '6604', '6500', '6398', '6337', '6339', '6370', '6371', '6380', '6432', '6487', '6499', '6523', '6548', '6584', '6637', '6659', '6676', '6694', '6704', '6707', '6708', '6732', '6728', '6717', '6724', '6725', '6727', '6737', '6744', '6746', '6745', '6772', '6778', '6772', '6763', '6751', '6734', '6745', '6755', '6756', '6753', '6765', '6756', '6739', '6739', '6741', '6744', '6763', '6772', '6756', '6752', '6775', '6783', '6773', '6780', '6787', '6768', '6768', '6768', '6755', '6751', '6738', '6751', '6758', '6765', '6780', '6770', '6786', '6816', '6810', '6812', '6826', '6816', '6793', '6800', '6809', '6789', '6782', '6802', '6807', '6802', '6812', '6824', '6850', '6884', '6896', '6878', '6874', '6885', '6887', '6879', '6889', '6906', '6895', '6895', '6906', '6922', '6943', '6962', '6970', '6977', '6987', '6978', '6984', '6988', '6984', '6971', '6970', '6978', '6976', '6978', '6981', '6978', '6974', '6988', '7010', '7010', '7000', '6997', '6988', '6981', '6987', '6969', '6953', '6959', '6953', '6935', '6935', '6930', '6902', '6889', '6895', '6879', '6853', '6833', '6809', '6782', '6762', '6755', '6739', '6722', '6728', '6710', '6697', '6687', '6686', '6666', '6660', '6656', '6643', '6642', '6636', '6611', '6602', '6599', '6596', '6596', '6594', '6584', '6581', '6588', '6589', '6582', '6579', '6578', '6591', '6592', '6591', '6578', '6562', '6555', '6575', '6577', '6561', '6555', '6555', '6553', '6565', '6579', '6570', '6561', '6564', '6568', '6561', '6587', '6592', '6577', '6575', '6594']

这里[723772887215724273687469]这些是峰/高元素

我需要找到:

Q=(lowest value on left of each peak/high element)
S=(lowest value on the right of each peak/high element)

到目前为止,我的计划(寻找高峰):

lead_2=['#Those values']
print (lead_2)
lead_2 = list(map(int, lead_2))
idx = range(len(lead_2))
pval = [1 - sum([i >= j for j in lead_2]) / (len(lead_2)+1) for i in lead_2]
stat_pval = [idx for idx,p in enumerate(pval) if p <= 0.01]
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]
idx_and_max_per_peak = []
Peak_value=[max(lead_2[grp[0]:grp[-1]+1]) for grp in grps]
print ('HighestPeak_value=',Peak_value)

示例法

让我们坐飞机吧

A=['22','21','22','23','24','25','26','27','28','27','24','15','23','22','32','30','28','20','27','17','22','28','42','40','35','22','16']

这里的峰值是(28,32,42),我需要每个峰值前后的低值

  • B=每个峰值左侧的21,22,17#低点
  • C=每个峰值右侧的15,20,16#低点

Tags: inforlenvaluestatlead峰值appendidxpeakgrp低点grpsconsecpval
1条回答
网友
1楼 ·

在列表中查找相对值的模式时,zip()函数非常有用。它允许您获得相邻值的配对(或三元组)

def findHighPeaks(A,count):
    # positions of values that are top of hills or bottom of valleys
    pivots   = [i for a,(i,b),c in zip(A,enumerate(A[1:],1),A[2:])
                                if a>b and b<c or a<b and b>c]

    # merge pivot positions into triples
    # representing the low-high-low or high-low-high indexes
    iWaves = [(left,mid,right) for left,mid,right
                               in  zip([0]+pivots,pivots,pivots[1:]+[len(A)-1])]
    
    # extract only peak values from patterns of hills and valleys
    peaks  = [(A[left],A[mid],A[right]) for left,mid,right in iWaves
                                        if A[left]<A[mid]]

    # find the highest peaks, and put them in a set
    highPeaks = set(sorted(peaks,key=lambda p:p[1])[-count:])

    # Return high peaks, in original order
    return [p for p in peaks if p in highPeaks]

# A = big list
    
Q,R,S = zip(*findHighPeaks(A,6)) # large example
print(R) # (7237, 7288, 7215, 7242, 7368, 7469) peaks
print(Q) # (6420, 6475, 6388, 6381, 6502, 6659) Low on the left
print(S) # (6076, 6180, 6452, 6018, 6176, 6337) Low on the right

A = ['22','21','22','23','24','25','26','27','28','27','24','15','23',
   '22','32','30','28','20','27','17','22','28','42','40','35','22','16']

Q,R,S = zip(*findHighPeaks(A,3)) # small example
print(R) # ('28', '32', '42') peaks
print(Q) # ('21', '22', '17') Low on the left
print(S) # ('15', '20', '16') Low on the right

这里是选择过程的视觉表示,它基于相对变化(增加/减少)

                                  HI                                        
                                 '28'                                   
                              '27'  '27'      HI    HI                     HI   
                           '26'        '24'  '23'  '32'                   '42'
                       '25'               '15'  '22'  '30'     HI      '28'  '40'
                    '24'                   LO    LO     '28'  '27'  '22'        '35'  
                 '23'                                      '20'  '17'              '22' 
        '22'  '22'                                          LO    LO                  '16'
           '21'
            LO

peaks:                           28           23    32         27          42       
            ||         -^^   -|| ^^-||-^^   ||-^^-||   -^^     ||
left:       21                            15     22         20    17
right:                                    15     22         20    17                   16