Is there a way to make this sequence creator faster? - python

I hope someone can give me some tips on how to speed up the following process. Its not really slow, but any time won could be very helpful.
from datetime import datetime
START_CLOCK = datetime.now()
TotalNumbcol = 266
NeighborsperColumn = [[3, 2, 5, 6, 7], [3, 6, 1, 7, 5, 4, 10, 11, 12, 13], [7, 2, 1, 6, 5, 11, 12, 13], [5, 10, 11, 9, 2, 6, 8, 12, 16, 17, 18, 19, 20], [6, 11, 4, 2, 12, 10, 1, 3, 7, 9, 13, 17, 18, 19, 20], [7, 12, 5, 2, 3, 13, 11, 1, 4, 10, 18, 19, 20], [13, 6, 3, 12, 2, 1, 5, 11, 19, 20], [9, 16, 17, 15, 4, 10, 14, 18, 24, 25, 26, 27, 28], [10, 17, 8, 4, 18, 16, 5, 11, 15, 19, 25, 26, 27, 28, 29], [11, 18, 9, 4, 5, 19, 17, 2, 6, 8, 12, 16, 20, 26, 27, 28, 29], [12, 19, 10, 5, 6, 20, 18, 4, 2, 3, 7, 9, 13, 17, 27, 28, 29], [13, 20, 11, 6, 7, 19, 5, 2, 3, 4, 10, 18, 28, 29], [12, 7, 20, 6, 2, 3, 5, 11, 19, 29], [15, 24, 25, 23, 8, 16, 22, 26, 34, 35, 36, 37, 38], [16, 25, 14, 8, 26, 24, 9, 17, 23, 27, 35, 36, 37, 38, 39], [17, 26, 15, 8, 9, 27, 25, 4, 10, 14, 18, 24, 28, 36, 37, 38, 39, 40], [18, 27, 16, 9, 10, 28, 26, 8, 4, 5, 11, 15, 19, 25, 29, 37, 38, 39, 40, 41], [19, 28, 17, 10, 11, 29, 27, 9, 4, 5, 6, 8, 12, 16, 20, 26, 38, 39, 40, 41], [20, 29, 18, 11, 12, 28, 10, 4, 5, 6, 7, 9, 13, 17, 27, 39, 40, 41], [19, 12, 13, 29, 11, 4, 5, 6, 7, 10, 18, 28, 40, 41], [22, 33, 34, 32, 23, 31, 35, 45, 46, 47, 48, 49], [23, 34, 21, 35, 33, 14, 24, 32, 36, 46, 47, 48, 49, 50], [24, 35, 22, 14, 36, 34, 15, 21, 25, 33, 37, 47, 48, 49, 50, 51], [25, 36, 23, 14, 15, 37, 35, 8, 16, 22, 26, 34, 38, 48, 49, 50, 51, 52], [26, 37, 24, 15, 16, 38, 36, 14, 8, 9, 17, 23, 27, 35, 39, 49, 50, 51, 52, 53], [27, 38, 25, 16, 17, 39, 37, 15, 8, 9, 10, 14, 18, 24, 28, 36, 40, 50, 51, 52, 53, 54], [28, 39, 26, 17, 18, 40, 38, 16, 8, 9, 10, 11, 15, 19, 25, 29, 37, 41, 51, 52, 53, 54], [29, 40, 27, 18, 19, 41, 39, 17, 8, 9, 10, 11, 12, 16, 20, 26, 38, 52, 53, 54], [41, 28, 19, 20, 40, 18, 9, 10, 11, 12, 13, 17, 27, 39, 53, 54], [31, 44, 45, 43, 32, 42, 46, 58, 59, 60, 61, 62], [32, 45, 30, 46, 44, 21, 33, 43, 47, 59, 60, 61, 62, 63], [33, 46, 31, 21, 47, 45, 22, 30, 34, 44, 48, 60, 61, 62, 63, 64], [34, 47, 32, 21, 22, 48, 46, 23, 31, 35, 45, 49, 61, 62, 63, 64, 65], [35, 48, 33, 22, 23, 49, 47, 21, 14, 24, 32, 36, 46, 50, 62, 63, 64, 65, 66], [36, 49, 34, 23, 24, 50, 48, 22, 14, 15, 21, 25, 33, 37, 47, 51, 63, 64, 65, 66, 67], [37, 50, 35, 24, 25, 51, 49, 23, 14, 15, 16, 22, 26, 34, 38, 48, 52, 64, 65, 66, 67, 68], [38, 51, 36, 25, 26, 52, 50, 24, 14, 15, 16, 17, 23, 27, 35, 39, 49, 53, 65, 66, 67, 68, 69], [39, 52, 37, 26, 27, 53, 51, 25, 14, 15, 16, 17, 18, 24, 28, 36, 40, 50, 54, 66, 67, 68, 69], [40, 53, 38, 27, 28, 54, 52, 26, 15, 16, 17, 18, 19, 25, 29, 37, 41, 51, 67, 68, 69], [41, 54, 39, 28, 29, 53, 27, 16, 17, 18, 19, 20, 26, 38, 52, 68, 69], [40, 29, 54, 28, 17, 18, 19, 20, 27, 39, 53, 69], [43, 58, 59, 57, 30, 44, 56, 60, 74, 75, 76, 77, 78], [44, 59, 42, 30, 60, 58, 31, 45, 57, 61, 75, 76, 77, 78, 79], [45, 60, 43, 30, 31, 61, 59, 32, 42, 46, 58, 62, 76, 77, 78, 79, 80], [46, 61, 44, 31, 32, 62, 60, 30, 21, 33, 43, 47, 59, 63, 77, 78, 79, 80, 81], [47, 62, 45, 32, 33, 63, 61, 31, 21, 22, 30, 34, 44, 48, 60, 64, 78, 79, 80, 81, 82], [48, 63, 46, 33, 34, 64, 62, 32, 21, 22, 23, 31, 35, 45, 49, 61, 65, 79, 80, 81, 82, 83], [49, 64, 47, 34, 35, 65, 63, 33, 21, 22, 23, 24, 32, 36, 46, 50, 62, 66, 80, 81, 82, 83, 84], [50, 65, 48, 35, 36, 66, 64, 34, 21, 22, 23, 24, 25, 33, 37, 47, 51, 63, 67, 81, 82, 83, 84, 85], [51, 66, 49, 36, 37, 67, 65, 35, 22, 23, 24, 25, 26, 34, 38, 48, 52, 64, 68, 82, 83, 84, 85], [52, 67, 50, 37, 38, 68, 66, 36, 23, 24, 25, 26, 27, 35, 39, 49, 53, 65, 69, 83, 84, 85], [53, 68, 51, 38, 39, 69, 67, 37, 24, 25, 26, 27, 28, 36, 40, 50, 54, 66, 84, 85], [54, 69, 52, 39, 40, 68, 38, 25, 26, 27, 28, 29, 37, 41, 51, 67, 85], [53, 40, 41, 69, 39, 26, 27, 28, 29, 38, 52, 68], [56, 73, 74, 72, 57, 71, 75, 90, 91, 92, 93, 94], [57, 74, 55, 75, 73, 42, 58, 72, 76, 91, 92, 93, 94, 95], [58, 75, 56, 42, 76, 74, 43, 55, 59, 73, 77, 92, 93, 94, 95, 96], [59, 76, 57, 42, 43, 77, 75, 30, 44, 56, 60, 74, 78, 93, 94, 95, 96, 97], [60, 77, 58, 43, 44, 78, 76, 42, 30, 31, 45, 57, 61, 75, 79, 94, 95, 96, 97, 98], [61, 78, 59, 44, 45, 79, 77, 43, 30, 31, 32, 42, 46, 58, 62, 76, 80, 95, 96, 97, 98, 99], [62, 79, 60, 45, 46, 80, 78, 44, 30, 31, 32, 33, 43, 47, 59, 63, 77, 81, 96, 97, 98, 99, 100], [63, 80, 61, 46, 47, 81, 79, 45, 30, 31, 32, 33, 34, 44, 48, 60, 64, 78, 82, 97, 98, 99, 100, 101], [64, 81, 62, 47, 48, 82, 80, 46, 31, 32, 33, 34, 35, 45, 49, 61, 65, 79, 83, 98, 99, 100, 101, 102], [65, 82, 63, 48, 49, 83, 81, 47, 32, 33, 34, 35, 36, 46, 50, 62, 66, 80, 84, 99, 100, 101, 102], [66, 83, 64, 49, 50, 84, 82, 48, 33, 34, 35, 36, 37, 47, 51, 63, 67, 81, 85, 100, 101, 102], [67, 84, 65, 50, 51, 85, 83, 49, 34, 35, 36, 37, 38, 48, 52, 64, 68, 82, 101, 102], [68, 85, 66, 51, 52, 84, 50, 35, 36, 37, 38, 39, 49, 53, 65, 69, 83, 102], [69, 67, 52, 53, 85, 51, 36, 37, 38, 39, 40, 50, 54, 66, 84], [68, 53, 54, 52, 37, 38, 39, 40, 41, 51, 67, 85], [71, 89, 90, 88, 72, 87, 91, 106, 107, 108, 109, 110], [72, 90, 70, 91, 89, 55, 73, 88, 92, 107, 108, 109, 110, 111], [73, 91, 71, 55, 92, 90, 56, 70, 74, 89, 93, 108, 109, 110, 111, 112], [74, 92, 72, 55, 56, 93, 91, 57, 71, 75, 90, 94, 109, 110, 111, 112, 113], [75, 93, 73, 56, 57, 94, 92, 55, 42, 58, 72, 76, 91, 95, 110, 111, 112, 113, 114], [76, 94, 74, 57, 58, 95, 93, 56, 42, 43, 55, 59, 73, 77, 92, 96, 111, 112, 113, 114, 115], [77, 95, 75, 58, 59, 96, 94, 57, 42, 43, 44, 56, 60, 74, 78, 93, 97, 112, 113, 114, 115, 116], [78, 96, 76, 59, 60, 97, 95, 58, 42, 43, 44, 45, 57, 61, 75, 79, 94, 98, 113, 114, 115, 116, 117], [79, 97, 77, 60, 61, 98, 96, 59, 42, 43, 44, 45, 46, 58, 62, 76, 80, 95, 99, 114, 115, 116, 117, 118], [80, 98, 78, 61, 62, 99, 97, 60, 43, 44, 45, 46, 47, 59, 63, 77, 81, 96, 100, 115, 116, 117, 118, 119], [81, 99, 79, 62, 63, 100, 98, 61, 44, 45, 46, 47, 48, 60, 64, 78, 82, 97, 101, 116, 117, 118, 119, 120], [82, 100, 80, 63, 64, 101, 99, 62, 45, 46, 47, 48, 49, 61, 65, 79, 83, 98, 102, 117, 118, 119, 120], [83, 101, 81, 64, 65, 102, 100, 63, 46, 47, 48, 49, 50, 62, 66, 80, 84, 99, 118, 119, 120], [84, 102, 82, 65, 66, 101, 64, 47, 48, 49, 50, 51, 63, 67, 81, 85, 100, 119, 120], [85, 83, 66, 67, 102, 65, 48, 49, 50, 51, 52, 64, 68, 82, 101, 120], [84, 67, 68, 66, 49, 50, 51, 52, 53, 65, 69, 83, 102], [87, 105, 106, 104, 88, 103, 107, 126, 127, 128, 129, 130], [88, 106, 86, 107, 105, 70, 89, 104, 108, 127, 128, 129, 130, 131], [89, 107, 87, 70, 108, 106, 71, 86, 90, 105, 109, 128, 129, 130, 131, 132], [90, 108, 88, 70, 71, 109, 107, 72, 87, 91, 106, 110, 129, 130, 131, 132, 133], [91, 109, 89, 71, 72, 110, 108, 70, 55, 73, 88, 92, 107, 111, 130, 131, 132, 133, 134], [92, 110, 90, 72, 73, 111, 109, 71, 55, 56, 70, 74, 89, 93, 108, 112, 131, 132, 133, 134, 135], [93, 111, 91, 73, 74, 112, 110, 72, 55, 56, 57, 71, 75, 90, 94, 109, 113, 132, 133, 134, 135, 136], [94, 112, 92, 74, 75, 113, 111, 73, 55, 56, 57, 58, 72, 76, 91, 95, 110, 114, 133, 134, 135, 136, 137], [95, 113, 93, 75, 76, 114, 112, 74, 55, 56, 57, 58, 59, 73, 77, 92, 96, 111, 115, 134, 135, 136, 137, 138], [96, 114, 94, 76, 77, 115, 113, 75, 56, 57, 58, 59, 60, 74, 78, 93, 97, 112, 116, 135, 136, 137, 138, 139], [97, 115, 95, 77, 78, 116, 114, 76, 57, 58, 59, 60, 61, 75, 79, 94, 98, 113, 117, 136, 137, 138, 139, 140], [98, 116, 96, 78, 79, 117, 115, 77, 58, 59, 60, 61, 62, 76, 80, 95, 99, 114, 118, 137, 138, 139, 140, 141], [99, 117, 97, 79, 80, 118, 116, 78, 59, 60, 61, 62, 63, 77, 81, 96, 100, 115, 119, 138, 139, 140, 141], [100, 118, 98, 80, 81, 119, 117, 79, 60, 61, 62, 63, 64, 78, 82, 97, 101, 116, 120, 139, 140, 141], [101, 119, 99, 81, 82, 120, 118, 80, 61, 62, 63, 64, 65, 79, 83, 98, 102, 117, 140, 141], [102, 120, 100, 82, 83, 119, 81, 62, 63, 64, 65, 66, 80, 84, 99, 118, 141], [101, 83, 84, 120, 82, 63, 64, 65, 66, 67, 81, 85, 100, 119], [104, 126, 127, 125, 86, 105, 124, 128, 149, 150, 151, 152, 153], [105, 127, 103, 86, 128, 126, 87, 106, 125, 129, 150, 151, 152, 153, 154], [106, 128, 104, 86, 87, 129, 127, 88, 103, 107, 126, 130, 151, 152, 153, 154, 155], [107, 129, 105, 87, 88, 130, 128, 86, 70, 89, 104, 108, 127, 131, 152, 153, 154, 155, 156], [108, 130, 106, 88, 89, 131, 129, 87, 70, 71, 86, 90, 105, 109, 128, 132, 153, 154, 155, 156, 157], [109, 131, 107, 89, 90, 132, 130, 88, 70, 71, 72, 87, 91, 106, 110, 129, 133, 154, 155, 156, 157, 158], [110, 132, 108, 90, 91, 133, 131, 89, 70, 71, 72, 73, 88, 92, 107, 111, 130, 134, 155, 156, 157, 158, 159], [111, 133, 109, 91, 92, 134, 132, 90, 70, 71, 72, 73, 74, 89, 93, 108, 112, 131, 135, 156, 157, 158, 159, 160], [112, 134, 110, 92, 93, 135, 133, 91, 71, 72, 73, 74, 75, 90, 94, 109, 113, 132, 136, 157, 158, 159, 160, 161], [113, 135, 111, 93, 94, 136, 134, 92, 72, 73, 74, 75, 76, 91, 95, 110, 114, 133, 137, 158, 159, 160, 161, 162], [114, 136, 112, 94, 95, 137, 135, 93, 73, 74, 75, 76, 77, 92, 96, 111, 115, 134, 138, 159, 160, 161, 162, 163], [115, 137, 113, 95, 96, 138, 136, 94, 74, 75, 76, 77, 78, 93, 97, 112, 116, 135, 139, 160, 161, 162, 163], [116, 138, 114, 96, 97, 139, 137, 95, 75, 76, 77, 78, 79, 94, 98, 113, 117, 136, 140, 161, 162, 163], [117, 139, 115, 97, 98, 140, 138, 96, 76, 77, 78, 79, 80, 95, 99, 114, 118, 137, 141, 162, 163], [118, 140, 116, 98, 99, 141, 139, 97, 77, 78, 79, 80, 81, 96, 100, 115, 119, 138, 163], [119, 141, 117, 99, 100, 140, 98, 78, 79, 80, 81, 82, 97, 101, 116, 120, 139], [120, 118, 100, 101, 141, 99, 79, 80, 81, 82, 83, 98, 102, 117, 140], [119, 101, 102, 100, 80, 81, 82, 83, 84, 99, 118, 141], [122, 146, 147, 145, 123, 144, 148, 169, 170, 171, 172, 173], [123, 147, 121, 148, 146, 124, 145, 149, 170, 171, 172, 173, 174], [124, 148, 122, 149, 147, 121, 125, 146, 150, 171, 172, 173, 174, 175], [125, 149, 123, 150, 148, 103, 122, 126, 147, 151, 172, 173, 174, 175, 176], [126, 150, 124, 103, 151, 149, 104, 123, 127, 148, 152, 173, 174, 175, 176, 177], [127, 151, 125, 103, 104, 152, 150, 86, 105, 124, 128, 149, 153, 174, 175, 176, 177, 178], [128, 152, 126, 104, 105, 153, 151, 103, 86, 87, 106, 125, 129, 150, 154, 175, 176, 177, 178, 179], [129, 153, 127, 105, 106, 154, 152, 104, 86, 87, 88, 103, 107, 126, 130, 151, 155, 176, 177, 178, 179, 180], [130, 154, 128, 106, 107, 155, 153, 105, 86, 87, 88, 89, 104, 108, 127, 131, 152, 156, 177, 178, 179, 180, 181], [131, 155, 129, 107, 108, 156, 154, 106, 86, 87, 88, 89, 90, 105, 109, 128, 132, 153, 157, 178, 179, 180, 181, 182], [132, 156, 130, 108, 109, 157, 155, 107, 87, 88, 89, 90, 91, 106, 110, 129, 133, 154, 158, 179, 180, 181, 182, 183], [133, 157, 131, 109, 110, 158, 156, 108, 88, 89, 90, 91, 92, 107, 111, 130, 134, 155, 159, 180, 181, 182, 183, 184], [134, 158, 132, 110, 111, 159, 157, 109, 89, 90, 91, 92, 93, 108, 112, 131, 135, 156, 160, 181, 182, 183, 184, 185], [135, 159, 133, 111, 112, 160, 158, 110, 90, 91, 92, 93, 94, 109, 113, 132, 136, 157, 161, 182, 183, 184, 185, 186], [136, 160, 134, 112, 113, 161, 159, 111, 91, 92, 93, 94, 95, 110, 114, 133, 137, 158, 162, 183, 184, 185, 186, 187], [137, 161, 135, 113, 114, 162, 160, 112, 92, 93, 94, 95, 96, 111, 115, 134, 138, 159, 163, 184, 185, 186, 187], [138, 162, 136, 114, 115, 163, 161, 113, 93, 94, 95, 96, 97, 112, 116, 135, 139, 160, 185, 186, 187], [139, 163, 137, 115, 116, 162, 114, 94, 95, 96, 97, 98, 113, 117, 136, 140, 161, 186, 187], [140, 138, 116, 117, 163, 115, 95, 96, 97, 98, 99, 114, 118, 137, 141, 162, 187], [141, 139, 117, 118, 116, 96, 97, 98, 99, 100, 115, 119, 138, 163], [140, 118, 119, 117, 97, 98, 99, 100, 101, 116, 120, 139], [143, 167, 168, 166, 144, 165, 169, 193, 194, 195, 196, 197], [144, 168, 142, 169, 167, 145, 166, 170, 194, 195, 196, 197, 198], [145, 169, 143, 170, 168, 121, 142, 146, 167, 171, 195, 196, 197, 198, 199], [146, 170, 144, 121, 171, 169, 122, 143, 147, 168, 172, 196, 197, 198, 199, 200], [147, 171, 145, 121, 122, 172, 170, 123, 144, 148, 169, 173, 197, 198, 199, 200, 201], [148, 172, 146, 122, 123, 173, 171, 121, 124, 145, 149, 170, 174, 198, 199, 200, 201, 202], [149, 173, 147, 123, 124, 174, 172, 122, 121, 125, 146, 150, 171, 175, 199, 200, 201, 202, 203], [150, 174, 148, 124, 125, 175, 173, 123, 103, 122, 126, 147, 151, 172, 176, 200, 201, 202, 203, 204], [151, 175, 149, 125, 126, 176, 174, 124, 103, 104, 123, 127, 148, 152, 173, 177, 201, 202, 203, 204, 205], [152, 176, 150, 126, 127, 177, 175, 125, 103, 104, 105, 124, 128, 149, 153, 174, 178, 202, 203, 204, 205, 206], [153, 177, 151, 127, 128, 178, 176, 126, 103, 104, 105, 106, 125, 129, 150, 154, 175, 179, 203, 204, 205, 206, 207], [154, 178, 152, 128, 129, 179, 177, 127, 103, 104, 105, 106, 107, 126, 130, 151, 155, 176, 180, 204, 205, 206, 207, 208], [155, 179, 153, 129, 130, 180, 178, 128, 104, 105, 106, 107, 108, 127, 131, 152, 156, 177, 181, 205, 206, 207, 208, 209], [156, 180, 154, 130, 131, 181, 179, 129, 105, 106, 107, 108, 109, 128, 132, 153, 157, 178, 182, 206, 207, 208, 209, 210], [157, 181, 155, 131, 132, 182, 180, 130, 106, 107, 108, 109, 110, 129, 133, 154, 158, 179, 183, 207, 208, 209, 210, 211], [158, 182, 156, 132, 133, 183, 181, 131, 107, 108, 109, 110, 111, 130, 134, 155, 159, 180, 184, 208, 209, 210, 211, 212], [159, 183, 157, 133, 134, 184, 182, 132, 108, 109, 110, 111, 112, 131, 135, 156, 160, 181, 185, 209, 210, 211, 212, 213], [160, 184, 158, 134, 135, 185, 183, 133, 109, 110, 111, 112, 113, 132, 136, 157, 161, 182, 186, 210, 211, 212, 213], [161, 185, 159, 135, 136, 186, 184, 134, 110, 111, 112, 113, 114, 133, 137, 158, 162, 183, 187, 211, 212, 213], [162, 186, 160, 136, 137, 187, 185, 135, 111, 112, 113, 114, 115, 134, 138, 159, 163, 184, 212, 213], [163, 187, 161, 137, 138, 186, 136, 112, 113, 114, 115, 116, 135, 139, 160, 185, 213], [162, 138, 139, 187, 137, 113, 114, 115, 116, 117, 136, 140, 161, 186], [165, 192, 193, 191, 166, 190, 194, 214, 215, 216, 217], [166, 193, 164, 194, 192, 142, 167, 191, 195, 214, 215, 216, 217, 218], [167, 194, 165, 142, 195, 193, 143, 164, 168, 192, 196, 215, 216, 217, 218, 219], [168, 195, 166, 142, 143, 196, 194, 144, 165, 169, 193, 197, 216, 217, 218, 219, 220], [169, 196, 167, 143, 144, 197, 195, 142, 145, 166, 170, 194, 198, 217, 218, 219, 220, 221], [170, 197, 168, 144, 145, 198, 196, 143, 121, 142, 146, 167, 171, 195, 199, 218, 219, 220, 221, 222], [171, 198, 169, 145, 146, 199, 197, 144, 121, 122, 143, 147, 168, 172, 196, 200, 219, 220, 221, 222, 223], [172, 199, 170, 146, 147, 200, 198, 145, 121, 122, 123, 144, 148, 169, 173, 197, 201, 220, 221, 222, 223, 224], [173, 200, 171, 147, 148, 201, 199, 146, 121, 122, 123, 124, 145, 149, 170, 174, 198, 202, 221, 222, 223, 224, 225], [174, 201, 172, 148, 149, 202, 200, 147, 121, 122, 123, 124, 125, 146, 150, 171, 175, 199, 203, 222, 223, 224, 225, 226], [175, 202, 173, 149, 150, 203, 201, 148, 122, 123, 124, 125, 126, 147, 151, 172, 176, 200, 204, 223, 224, 225, 226, 227], [176, 203, 174, 150, 151, 204, 202, 149, 123, 124, 125, 126, 127, 148, 152, 173, 177, 201, 205, 224, 225, 226, 227, 228], [177, 204, 175, 151, 152, 205, 203, 150, 124, 125, 126, 127, 128, 149, 153, 174, 178, 202, 206, 225, 226, 227, 228, 229], [178, 205, 176, 152, 153, 206, 204, 151, 125, 126, 127, 128, 129, 150, 154, 175, 179, 203, 207, 226, 227, 228, 229, 230], [179, 206, 177, 153, 154, 207, 205, 152, 126, 127, 128, 129, 130, 151, 155, 176, 180, 204, 208, 227, 228, 229, 230, 231], [180, 207, 178, 154, 155, 208, 206, 153, 127, 128, 129, 130, 131, 152, 156, 177, 181, 205, 209, 228, 229, 230, 231], [181, 208, 179, 155, 156, 209, 207, 154, 128, 129, 130, 131, 132, 153, 157, 178, 182, 206, 210, 229, 230, 231], [182, 209, 180, 156, 157, 210, 208, 155, 129, 130, 131, 132, 133, 154, 158, 179, 183, 207, 211, 230, 231], [183, 210, 181, 157, 158, 211, 209, 156, 130, 131, 132, 133, 134, 155, 159, 180, 184, 208, 212, 231], [184, 211, 182, 158, 159, 212, 210, 157, 131, 132, 133, 134, 135, 156, 160, 181, 185, 209, 213], [185, 212, 183, 159, 160, 213, 211, 158, 132, 133, 134, 135, 136, 157, 161, 182, 186, 210], [186, 213, 184, 160, 161, 212, 159, 133, 134, 135, 136, 137, 158, 162, 183, 187, 211], [187, 185, 161, 162, 213, 160, 134, 135, 136, 137, 138, 159, 163, 184, 212], [186, 162, 163, 161, 135, 136, 137, 138, 139, 160, 185, 213], [189, 190], [190, 188, 191, 214], [191, 189, 214, 164, 188, 192, 215, 232], [192, 214, 190, 164, 215, 165, 189, 193, 216, 232, 233], [193, 215, 191, 164, 165, 216, 214, 166, 190, 194, 217, 232, 233, 234], [194, 216, 192, 165, 166, 217, 215, 164, 142, 167, 191, 195, 214, 218, 232, 233, 234, 235], [195, 217, 193, 166, 167, 218, 216, 165, 142, 143, 164, 168, 192, 196, 215, 219, 232, 233, 234, 235, 236], [196, 218, 194, 167, 168, 219, 217, 166, 142, 143, 144, 165, 169, 193, 197, 216, 220, 233, 234, 235, 236, 237], [197, 219, 195, 168, 169, 220, 218, 167, 142, 143, 144, 145, 166, 170, 194, 198, 217, 221, 234, 235, 236, 237, 238], [198, 220, 196, 169, 170, 221, 219, 168, 142, 143, 144, 145, 146, 167, 171, 195, 199, 218, 222, 235, 236, 237, 238, 239], [199, 221, 197, 170, 171, 222, 220, 169, 143, 144, 145, 146, 147, 168, 172, 196, 200, 219, 223, 236, 237, 238, 239, 240], [200, 222, 198, 171, 172, 223, 221, 170, 144, 145, 146, 147, 148, 169, 173, 197, 201, 220, 224, 237, 238, 239, 240, 241], [201, 223, 199, 172, 173, 224, 222, 171, 145, 146, 147, 148, 149, 170, 174, 198, 202, 221, 225, 238, 239, 240, 241, 242], [202, 224, 200, 173, 174, 225, 223, 172, 146, 147, 148, 149, 150, 171, 175, 199, 203, 222, 226, 239, 240, 241, 242, 243], [203, 225, 201, 174, 175, 226, 224, 173, 147, 148, 149, 150, 151, 172, 176, 200, 204, 223, 227, 240, 241, 242, 243, 244], [204, 226, 202, 175, 176, 227, 225, 174, 148, 149, 150, 151, 152, 173, 177, 201, 205, 224, 228, 241, 242, 243, 244, 245], [205, 227, 203, 176, 177, 228, 226, 175, 149, 150, 151, 152, 153, 174, 178, 202, 206, 225, 229, 242, 243, 244, 245], [206, 228, 204, 177, 178, 229, 227, 176, 150, 151, 152, 153, 154, 175, 179, 203, 207, 226, 230, 243, 244, 245], [207, 229, 205, 178, 179, 230, 228, 177, 151, 152, 153, 154, 155, 176, 180, 204, 208, 227, 231, 244, 245], [208, 230, 206, 179, 180, 231, 229, 178, 152, 153, 154, 155, 156, 177, 181, 205, 209, 228, 245], [209, 231, 207, 180, 181, 230, 179, 153, 154, 155, 156, 157, 178, 182, 206, 210, 229], [210, 208, 181, 182, 231, 180, 154, 155, 156, 157, 158, 179, 183, 207, 211, 230], [211, 209, 182, 183, 181, 155, 156, 157, 158, 159, 180, 184, 208, 212, 231], [212, 210, 183, 184, 182, 156, 157, 158, 159, 160, 181, 185, 209, 213], [213, 211, 184, 185, 183, 157, 158, 159, 160, 161, 182, 186, 210], [212, 185, 186, 184, 158, 159, 160, 161, 162, 183, 187, 211], [215, 191, 192, 232, 190, 164, 165, 189, 193, 216, 233], [216, 232, 214, 192, 193, 233, 191, 164, 165, 166, 190, 194, 217, 234, 246], [217, 233, 215, 193, 194, 234, 232, 192, 164, 165, 166, 167, 191, 195, 214, 218, 235, 246, 247], [218, 234, 216, 194, 195, 235, 233, 193, 164, 165, 166, 167, 168, 192, 196, 215, 219, 232, 236, 246, 247, 248], [219, 235, 217, 195, 196, 236, 234, 194, 165, 166, 167, 168, 169, 193, 197, 216, 220, 233, 237, 246, 247, 248, 249], [220, 236, 218, 196, 197, 237, 235, 195, 166, 167, 168, 169, 170, 194, 198, 217, 221, 234, 238, 246, 247, 248, 249, 250], [221, 237, 219, 197, 198, 238, 236, 196, 167, 168, 169, 170, 171, 195, 199, 218, 222, 235, 239, 247, 248, 249, 250, 251], [222, 238, 220, 198, 199, 239, 237, 197, 168, 169, 170, 171, 172, 196, 200, 219, 223, 236, 240, 248, 249, 250, 251, 252], [223, 239, 221, 199, 200, 240, 238, 198, 169, 170, 171, 172, 173, 197, 201, 220, 224, 237, 241, 249, 250, 251, 252, 253], [224, 240, 222, 200, 201, 241, 239, 199, 170, 171, 172, 173, 174, 198, 202, 221, 225, 238, 242, 250, 251, 252, 253, 254], [225, 241, 223, 201, 202, 242, 240, 200, 171, 172, 173, 174, 175, 199, 203, 222, 226, 239, 243, 251, 252, 253, 254, 255], [226, 242, 224, 202, 203, 243, 241, 201, 172, 173, 174, 175, 176, 200, 204, 223, 227, 240, 244, 252, 253, 254, 255], [227, 243, 225, 203, 204, 244, 242, 202, 173, 174, 175, 176, 177, 201, 205, 224, 228, 241, 245, 253, 254, 255], [228, 244, 226, 204, 205, 245, 243, 203, 174, 175, 176, 177, 178, 202, 206, 225, 229, 242, 254, 255], [229, 245, 227, 205, 206, 244, 204, 175, 176, 177, 178, 179, 203, 207, 226, 230, 243, 255], [230, 228, 206, 207, 245, 205, 176, 177, 178, 179, 180, 204, 208, 227, 231, 244], [231, 229, 207, 208, 206, 177, 178, 179, 180, 181, 205, 209, 228, 245], [230, 208, 209, 207, 178, 179, 180, 181, 182, 206, 210, 229], [233, 215, 216, 214, 190, 191, 192, 193, 194, 217, 234, 246], [234, 232, 216, 217, 246, 215, 191, 192, 193, 194, 195, 214, 218, 235, 247, 256], [235, 246, 233, 217, 218, 247, 216, 192, 193, 194, 195, 196, 215, 219, 232, 236, 248, 256, 257], [236, 247, 234, 218, 219, 248, 246, 217, 193, 194, 195, 196, 197, 216, 220, 233, 237, 249, 256, 257, 258], [237, 248, 235, 219, 220, 249, 247, 218, 194, 195, 196, 197, 198, 217, 221, 234, 238, 246, 250, 256, 257, 258, 259], [238, 249, 236, 220, 221, 250, 248, 219, 195, 196, 197, 198, 199, 218, 222, 235, 239, 247, 251, 256, 257, 258, 259, 260], [239, 250, 237, 221, 222, 251, 249, 220, 196, 197, 198, 199, 200, 219, 223, 236, 240, 248, 252, 257, 258, 259, 260, 261], [240, 251, 238, 222, 223, 252, 250, 221, 197, 198, 199, 200, 201, 220, 224, 237, 241, 249, 253, 258, 259, 260, 261, 262], [241, 252, 239, 223, 224, 253, 251, 222, 198, 199, 200, 201, 202, 221, 225, 238, 242, 250, 254, 259, 260, 261, 262], [242, 253, 240, 224, 225, 254, 252, 223, 199, 200, 201, 202, 203, 222, 226, 239, 243, 251, 255, 260, 261, 262], [243, 254, 241, 225, 226, 255, 253, 224, 200, 201, 202, 203, 204, 223, 227, 240, 244, 252, 261, 262], [244, 255, 242, 226, 227, 254, 225, 201, 202, 203, 204, 205, 224, 228, 241, 245, 253, 262], [245, 243, 227, 228, 255, 226, 202, 203, 204, 205, 206, 225, 229, 242, 254], [244, 228, 229, 227, 203, 204, 205, 206, 207, 226, 230, 243, 255], [247, 234, 235, 256, 233, 215, 216, 217, 218, 219, 232, 236, 248, 257, 263], [248, 256, 246, 235, 236, 257, 234, 216, 217, 218, 219, 220, 233, 237, 249, 258, 263, 264], [249, 257, 247, 236, 237, 258, 256, 235, 217, 218, 219, 220, 221, 234, 238, 246, 250, 259, 263, 264, 265], [250, 258, 248, 237, 238, 259, 257, 236, 218, 219, 220, 221, 222, 235, 239, 247, 251, 256, 260, 263, 264, 265, 266], [251, 259, 249, 238, 239, 260, 258, 237, 219, 220, 221, 222, 223, 236, 240, 248, 252, 257, 261, 263, 264, 265, 266], [252, 260, 250, 239, 240, 261, 259, 238, 220, 221, 222, 223, 224, 237, 241, 249, 253, 258, 262, 264, 265, 266], [253, 261, 251, 240, 241, 262, 260, 239, 221, 222, 223, 224, 225, 238, 242, 250, 254, 259, 265, 266], [254, 262, 252, 241, 242, 261, 240, 222, 223, 224, 225, 226, 239, 243, 251, 255, 260, 266], [255, 253, 242, 243, 262, 241, 223, 224, 225, 226, 227, 240, 244, 252, 261], [254, 243, 244, 242, 224, 225, 226, 227, 228, 241, 245, 253, 262], [257, 247, 248, 263, 246, 233, 234, 235, 236, 237, 249, 258, 264], [258, 263, 256, 248, 249, 264, 247, 234, 235, 236, 237, 238, 246, 250, 259, 265], [259, 264, 257, 249, 250, 265, 263, 248, 235, 236, 237, 238, 239, 247, 251, 256, 260, 266], [260, 265, 258, 250, 251, 266, 264, 249, 236, 237, 238, 239, 240, 248, 252, 257, 261, 263], [261, 266, 259, 251, 252, 265, 250, 237, 238, 239, 240, 241, 249, 253, 258, 262, 264], [262, 260, 252, 253, 266, 251, 238, 239, 240, 241, 242, 250, 254, 259, 265], [261, 253, 254, 252, 239, 240, 241, 242, 243, 251, 255, 260, 266], [264, 257, 258, 256, 246, 247, 248, 249, 250, 259, 265], [265, 263, 258, 259, 257, 247, 248, 249, 250, 251, 256, 260, 266], [266, 264, 259, 260, 258, 248, 249, 250, 251, 252, 257, 261, 263], [265, 260, 261, 259, 249, 250, 251, 252, 253, 258, 262, 264]]
from random import shuffle
Column_Numbers2 = list(np.arange(1,TotalNumbcol+1,1))
Chosen_Columns2 = []
shuffle(Column_Numbers2)
rand = Column_Numbers2.pop()
Chosen_Columns2.append(rand)
while Column_Numbers2:
for i in range(rand-1,rand):
rand = NeighborsperColumn[i]
rand = [x for x in rand if x not in Chosen_Columns2]
shuffle(rand)
try:
rand = rand.pop()
Chosen_Columns2.append(rand)
Column_Numbers2.remove(rand)
except IndexError:
rand = Column_Numbers2.pop()
Chosen_Columns2.append(rand)
print Column_Numbers2
print Chosen_Columns2
END_CLOCK = datetime.now()
DELTA_TIME = END_CLOCK - START_CLOCK
print DELTA_TIME
Time measured is usually around 0.018 sec (on my computer that is).
NeighborsperColumn represents all neighbors that are allowed to be chosen next after a certain column. Their index corresponds to the number from Column_Numbers2 -1.
Now I wonder if there is a possibility to speed this up by doing some things in a different way. The results should be a sequence of all column numbers from Column_Numbers2 (numbers 1 to 266 in this case). This script does work, but I have to do many iterations with it so I'm wondering if there's a way to save some time.
Thanks

Thank you for the working example. This allowed my to help you. Here is some code. The basic idea is to replace:
shuffle(Column_Numbers2)
with
Column_Numbers2 = np.random.permutation(Column_Numbers2).tolist()
This makes your code about 3 times faster:
from datetime import datetime
import numpy as np
from random import shuffle
START_CLOCK = datetime.now()
TotalNumbcol = 266
NeighborsperColumn = [[3, 2, 5, 6, 7], [3, 6, 1, 7, 5, 4, 10, 11, 12, 13], [7, 2, 1, 6, 5, 11, 12, 13], [5, 10, 11, 9, 2, 6, 8, 12, 16, 17, 18, 19, 20], [6, 11, 4, 2, 12, 10, 1, 3, 7, 9, 13, 17, 18, 19, 20], [7, 12, 5, 2, 3, 13, 11, 1, 4, 10, 18, 19, 20], [13, 6, 3, 12, 2, 1, 5, 11, 19, 20], [9, 16, 17, 15, 4, 10, 14, 18, 24, 25, 26, 27, 28], [10, 17, 8, 4, 18, 16, 5, 11, 15, 19, 25, 26, 27, 28, 29], [11, 18, 9, 4, 5, 19, 17, 2, 6, 8, 12, 16, 20, 26, 27, 28, 29], [12, 19, 10, 5, 6, 20, 18, 4, 2, 3, 7, 9, 13, 17, 27, 28, 29], [13, 20, 11, 6, 7, 19, 5, 2, 3, 4, 10, 18, 28, 29], [12, 7, 20, 6, 2, 3, 5, 11, 19, 29], [15, 24, 25, 23, 8, 16, 22, 26, 34, 35, 36, 37, 38], [16, 25, 14, 8, 26, 24, 9, 17, 23, 27, 35, 36, 37, 38, 39], [17, 26, 15, 8, 9, 27, 25, 4, 10, 14, 18, 24, 28, 36, 37, 38, 39, 40], [18, 27, 16, 9, 10, 28, 26, 8, 4, 5, 11, 15, 19, 25, 29, 37, 38, 39, 40, 41], [19, 28, 17, 10, 11, 29, 27, 9, 4, 5, 6, 8, 12, 16, 20, 26, 38, 39, 40, 41], [20, 29, 18, 11, 12, 28, 10, 4, 5, 6, 7, 9, 13, 17, 27, 39, 40, 41], [19, 12, 13, 29, 11, 4, 5, 6, 7, 10, 18, 28, 40, 41], [22, 33, 34, 32, 23, 31, 35, 45, 46, 47, 48, 49], [23, 34, 21, 35, 33, 14, 24, 32, 36, 46, 47, 48, 49, 50], [24, 35, 22, 14, 36, 34, 15, 21, 25, 33, 37, 47, 48, 49, 50, 51], [25, 36, 23, 14, 15, 37, 35, 8, 16, 22, 26, 34, 38, 48, 49, 50, 51, 52], [26, 37, 24, 15, 16, 38, 36, 14, 8, 9, 17, 23, 27, 35, 39, 49, 50, 51, 52, 53], [27, 38, 25, 16, 17, 39, 37, 15, 8, 9, 10, 14, 18, 24, 28, 36, 40, 50, 51, 52, 53, 54], [28, 39, 26, 17, 18, 40, 38, 16, 8, 9, 10, 11, 15, 19, 25, 29, 37, 41, 51, 52, 53, 54], [29, 40, 27, 18, 19, 41, 39, 17, 8, 9, 10, 11, 12, 16, 20, 26, 38, 52, 53, 54], [41, 28, 19, 20, 40, 18, 9, 10, 11, 12, 13, 17, 27, 39, 53, 54], [31, 44, 45, 43, 32, 42, 46, 58, 59, 60, 61, 62], [32, 45, 30, 46, 44, 21, 33, 43, 47, 59, 60, 61, 62, 63], [33, 46, 31, 21, 47, 45, 22, 30, 34, 44, 48, 60, 61, 62, 63, 64], [34, 47, 32, 21, 22, 48, 46, 23, 31, 35, 45, 49, 61, 62, 63, 64, 65], [35, 48, 33, 22, 23, 49, 47, 21, 14, 24, 32, 36, 46, 50, 62, 63, 64, 65, 66], [36, 49, 34, 23, 24, 50, 48, 22, 14, 15, 21, 25, 33, 37, 47, 51, 63, 64, 65, 66, 67], [37, 50, 35, 24, 25, 51, 49, 23, 14, 15, 16, 22, 26, 34, 38, 48, 52, 64, 65, 66, 67, 68], [38, 51, 36, 25, 26, 52, 50, 24, 14, 15, 16, 17, 23, 27, 35, 39, 49, 53, 65, 66, 67, 68, 69], [39, 52, 37, 26, 27, 53, 51, 25, 14, 15, 16, 17, 18, 24, 28, 36, 40, 50, 54, 66, 67, 68, 69], [40, 53, 38, 27, 28, 54, 52, 26, 15, 16, 17, 18, 19, 25, 29, 37, 41, 51, 67, 68, 69], [41, 54, 39, 28, 29, 53, 27, 16, 17, 18, 19, 20, 26, 38, 52, 68, 69], [40, 29, 54, 28, 17, 18, 19, 20, 27, 39, 53, 69], [43, 58, 59, 57, 30, 44, 56, 60, 74, 75, 76, 77, 78], [44, 59, 42, 30, 60, 58, 31, 45, 57, 61, 75, 76, 77, 78, 79], [45, 60, 43, 30, 31, 61, 59, 32, 42, 46, 58, 62, 76, 77, 78, 79, 80], [46, 61, 44, 31, 32, 62, 60, 30, 21, 33, 43, 47, 59, 63, 77, 78, 79, 80, 81], [47, 62, 45, 32, 33, 63, 61, 31, 21, 22, 30, 34, 44, 48, 60, 64, 78, 79, 80, 81, 82], [48, 63, 46, 33, 34, 64, 62, 32, 21, 22, 23, 31, 35, 45, 49, 61, 65, 79, 80, 81, 82, 83], [49, 64, 47, 34, 35, 65, 63, 33, 21, 22, 23, 24, 32, 36, 46, 50, 62, 66, 80, 81, 82, 83, 84], [50, 65, 48, 35, 36, 66, 64, 34, 21, 22, 23, 24, 25, 33, 37, 47, 51, 63, 67, 81, 82, 83, 84, 85], [51, 66, 49, 36, 37, 67, 65, 35, 22, 23, 24, 25, 26, 34, 38, 48, 52, 64, 68, 82, 83, 84, 85], [52, 67, 50, 37, 38, 68, 66, 36, 23, 24, 25, 26, 27, 35, 39, 49, 53, 65, 69, 83, 84, 85], [53, 68, 51, 38, 39, 69, 67, 37, 24, 25, 26, 27, 28, 36, 40, 50, 54, 66, 84, 85], [54, 69, 52, 39, 40, 68, 38, 25, 26, 27, 28, 29, 37, 41, 51, 67, 85], [53, 40, 41, 69, 39, 26, 27, 28, 29, 38, 52, 68], [56, 73, 74, 72, 57, 71, 75, 90, 91, 92, 93, 94], [57, 74, 55, 75, 73, 42, 58, 72, 76, 91, 92, 93, 94, 95], [58, 75, 56, 42, 76, 74, 43, 55, 59, 73, 77, 92, 93, 94, 95, 96], [59, 76, 57, 42, 43, 77, 75, 30, 44, 56, 60, 74, 78, 93, 94, 95, 96, 97], [60, 77, 58, 43, 44, 78, 76, 42, 30, 31, 45, 57, 61, 75, 79, 94, 95, 96, 97, 98], [61, 78, 59, 44, 45, 79, 77, 43, 30, 31, 32, 42, 46, 58, 62, 76, 80, 95, 96, 97, 98, 99], [62, 79, 60, 45, 46, 80, 78, 44, 30, 31, 32, 33, 43, 47, 59, 63, 77, 81, 96, 97, 98, 99, 100], [63, 80, 61, 46, 47, 81, 79, 45, 30, 31, 32, 33, 34, 44, 48, 60, 64, 78, 82, 97, 98, 99, 100, 101], [64, 81, 62, 47, 48, 82, 80, 46, 31, 32, 33, 34, 35, 45, 49, 61, 65, 79, 83, 98, 99, 100, 101, 102], [65, 82, 63, 48, 49, 83, 81, 47, 32, 33, 34, 35, 36, 46, 50, 62, 66, 80, 84, 99, 100, 101, 102], [66, 83, 64, 49, 50, 84, 82, 48, 33, 34, 35, 36, 37, 47, 51, 63, 67, 81, 85, 100, 101, 102], [67, 84, 65, 50, 51, 85, 83, 49, 34, 35, 36, 37, 38, 48, 52, 64, 68, 82, 101, 102], [68, 85, 66, 51, 52, 84, 50, 35, 36, 37, 38, 39, 49, 53, 65, 69, 83, 102], [69, 67, 52, 53, 85, 51, 36, 37, 38, 39, 40, 50, 54, 66, 84], [68, 53, 54, 52, 37, 38, 39, 40, 41, 51, 67, 85], [71, 89, 90, 88, 72, 87, 91, 106, 107, 108, 109, 110], [72, 90, 70, 91, 89, 55, 73, 88, 92, 107, 108, 109, 110, 111], [73, 91, 71, 55, 92, 90, 56, 70, 74, 89, 93, 108, 109, 110, 111, 112], [74, 92, 72, 55, 56, 93, 91, 57, 71, 75, 90, 94, 109, 110, 111, 112, 113], [75, 93, 73, 56, 57, 94, 92, 55, 42, 58, 72, 76, 91, 95, 110, 111, 112, 113, 114], [76, 94, 74, 57, 58, 95, 93, 56, 42, 43, 55, 59, 73, 77, 92, 96, 111, 112, 113, 114, 115], [77, 95, 75, 58, 59, 96, 94, 57, 42, 43, 44, 56, 60, 74, 78, 93, 97, 112, 113, 114, 115, 116], [78, 96, 76, 59, 60, 97, 95, 58, 42, 43, 44, 45, 57, 61, 75, 79, 94, 98, 113, 114, 115, 116, 117], [79, 97, 77, 60, 61, 98, 96, 59, 42, 43, 44, 45, 46, 58, 62, 76, 80, 95, 99, 114, 115, 116, 117, 118], [80, 98, 78, 61, 62, 99, 97, 60, 43, 44, 45, 46, 47, 59, 63, 77, 81, 96, 100, 115, 116, 117, 118, 119], [81, 99, 79, 62, 63, 100, 98, 61, 44, 45, 46, 47, 48, 60, 64, 78, 82, 97, 101, 116, 117, 118, 119, 120], [82, 100, 80, 63, 64, 101, 99, 62, 45, 46, 47, 48, 49, 61, 65, 79, 83, 98, 102, 117, 118, 119, 120], [83, 101, 81, 64, 65, 102, 100, 63, 46, 47, 48, 49, 50, 62, 66, 80, 84, 99, 118, 119, 120], [84, 102, 82, 65, 66, 101, 64, 47, 48, 49, 50, 51, 63, 67, 81, 85, 100, 119, 120], [85, 83, 66, 67, 102, 65, 48, 49, 50, 51, 52, 64, 68, 82, 101, 120], [84, 67, 68, 66, 49, 50, 51, 52, 53, 65, 69, 83, 102], [87, 105, 106, 104, 88, 103, 107, 126, 127, 128, 129, 130], [88, 106, 86, 107, 105, 70, 89, 104, 108, 127, 128, 129, 130, 131], [89, 107, 87, 70, 108, 106, 71, 86, 90, 105, 109, 128, 129, 130, 131, 132], [90, 108, 88, 70, 71, 109, 107, 72, 87, 91, 106, 110, 129, 130, 131, 132, 133], [91, 109, 89, 71, 72, 110, 108, 70, 55, 73, 88, 92, 107, 111, 130, 131, 132, 133, 134], [92, 110, 90, 72, 73, 111, 109, 71, 55, 56, 70, 74, 89, 93, 108, 112, 131, 132, 133, 134, 135], [93, 111, 91, 73, 74, 112, 110, 72, 55, 56, 57, 71, 75, 90, 94, 109, 113, 132, 133, 134, 135, 136], [94, 112, 92, 74, 75, 113, 111, 73, 55, 56, 57, 58, 72, 76, 91, 95, 110, 114, 133, 134, 135, 136, 137], [95, 113, 93, 75, 76, 114, 112, 74, 55, 56, 57, 58, 59, 73, 77, 92, 96, 111, 115, 134, 135, 136, 137, 138], [96, 114, 94, 76, 77, 115, 113, 75, 56, 57, 58, 59, 60, 74, 78, 93, 97, 112, 116, 135, 136, 137, 138, 139], [97, 115, 95, 77, 78, 116, 114, 76, 57, 58, 59, 60, 61, 75, 79, 94, 98, 113, 117, 136, 137, 138, 139, 140], [98, 116, 96, 78, 79, 117, 115, 77, 58, 59, 60, 61, 62, 76, 80, 95, 99, 114, 118, 137, 138, 139, 140, 141], [99, 117, 97, 79, 80, 118, 116, 78, 59, 60, 61, 62, 63, 77, 81, 96, 100, 115, 119, 138, 139, 140, 141], [100, 118, 98, 80, 81, 119, 117, 79, 60, 61, 62, 63, 64, 78, 82, 97, 101, 116, 120, 139, 140, 141], [101, 119, 99, 81, 82, 120, 118, 80, 61, 62, 63, 64, 65, 79, 83, 98, 102, 117, 140, 141], [102, 120, 100, 82, 83, 119, 81, 62, 63, 64, 65, 66, 80, 84, 99, 118, 141], [101, 83, 84, 120, 82, 63, 64, 65, 66, 67, 81, 85, 100, 119], [104, 126, 127, 125, 86, 105, 124, 128, 149, 150, 151, 152, 153], [105, 127, 103, 86, 128, 126, 87, 106, 125, 129, 150, 151, 152, 153, 154], [106, 128, 104, 86, 87, 129, 127, 88, 103, 107, 126, 130, 151, 152, 153, 154, 155], [107, 129, 105, 87, 88, 130, 128, 86, 70, 89, 104, 108, 127, 131, 152, 153, 154, 155, 156], [108, 130, 106, 88, 89, 131, 129, 87, 70, 71, 86, 90, 105, 109, 128, 132, 153, 154, 155, 156, 157], [109, 131, 107, 89, 90, 132, 130, 88, 70, 71, 72, 87, 91, 106, 110, 129, 133, 154, 155, 156, 157, 158], [110, 132, 108, 90, 91, 133, 131, 89, 70, 71, 72, 73, 88, 92, 107, 111, 130, 134, 155, 156, 157, 158, 159], [111, 133, 109, 91, 92, 134, 132, 90, 70, 71, 72, 73, 74, 89, 93, 108, 112, 131, 135, 156, 157, 158, 159, 160], [112, 134, 110, 92, 93, 135, 133, 91, 71, 72, 73, 74, 75, 90, 94, 109, 113, 132, 136, 157, 158, 159, 160, 161], [113, 135, 111, 93, 94, 136, 134, 92, 72, 73, 74, 75, 76, 91, 95, 110, 114, 133, 137, 158, 159, 160, 161, 162], [114, 136, 112, 94, 95, 137, 135, 93, 73, 74, 75, 76, 77, 92, 96, 111, 115, 134, 138, 159, 160, 161, 162, 163], [115, 137, 113, 95, 96, 138, 136, 94, 74, 75, 76, 77, 78, 93, 97, 112, 116, 135, 139, 160, 161, 162, 163], [116, 138, 114, 96, 97, 139, 137, 95, 75, 76, 77, 78, 79, 94, 98, 113, 117, 136, 140, 161, 162, 163], [117, 139, 115, 97, 98, 140, 138, 96, 76, 77, 78, 79, 80, 95, 99, 114, 118, 137, 141, 162, 163], [118, 140, 116, 98, 99, 141, 139, 97, 77, 78, 79, 80, 81, 96, 100, 115, 119, 138, 163], [119, 141, 117, 99, 100, 140, 98, 78, 79, 80, 81, 82, 97, 101, 116, 120, 139], [120, 118, 100, 101, 141, 99, 79, 80, 81, 82, 83, 98, 102, 117, 140], [119, 101, 102, 100, 80, 81, 82, 83, 84, 99, 118, 141], [122, 146, 147, 145, 123, 144, 148, 169, 170, 171, 172, 173], [123, 147, 121, 148, 146, 124, 145, 149, 170, 171, 172, 173, 174], [124, 148, 122, 149, 147, 121, 125, 146, 150, 171, 172, 173, 174, 175], [125, 149, 123, 150, 148, 103, 122, 126, 147, 151, 172, 173, 174, 175, 176], [126, 150, 124, 103, 151, 149, 104, 123, 127, 148, 152, 173, 174, 175, 176, 177], [127, 151, 125, 103, 104, 152, 150, 86, 105, 124, 128, 149, 153, 174, 175, 176, 177, 178], [128, 152, 126, 104, 105, 153, 151, 103, 86, 87, 106, 125, 129, 150, 154, 175, 176, 177, 178, 179], [129, 153, 127, 105, 106, 154, 152, 104, 86, 87, 88, 103, 107, 126, 130, 151, 155, 176, 177, 178, 179, 180], [130, 154, 128, 106, 107, 155, 153, 105, 86, 87, 88, 89, 104, 108, 127, 131, 152, 156, 177, 178, 179, 180, 181], [131, 155, 129, 107, 108, 156, 154, 106, 86, 87, 88, 89, 90, 105, 109, 128, 132, 153, 157, 178, 179, 180, 181, 182], [132, 156, 130, 108, 109, 157, 155, 107, 87, 88, 89, 90, 91, 106, 110, 129, 133, 154, 158, 179, 180, 181, 182, 183], [133, 157, 131, 109, 110, 158, 156, 108, 88, 89, 90, 91, 92, 107, 111, 130, 134, 155, 159, 180, 181, 182, 183, 184], [134, 158, 132, 110, 111, 159, 157, 109, 89, 90, 91, 92, 93, 108, 112, 131, 135, 156, 160, 181, 182, 183, 184, 185], [135, 159, 133, 111, 112, 160, 158, 110, 90, 91, 92, 93, 94, 109, 113, 132, 136, 157, 161, 182, 183, 184, 185, 186], [136, 160, 134, 112, 113, 161, 159, 111, 91, 92, 93, 94, 95, 110, 114, 133, 137, 158, 162, 183, 184, 185, 186, 187], [137, 161, 135, 113, 114, 162, 160, 112, 92, 93, 94, 95, 96, 111, 115, 134, 138, 159, 163, 184, 185, 186, 187], [138, 162, 136, 114, 115, 163, 161, 113, 93, 94, 95, 96, 97, 112, 116, 135, 139, 160, 185, 186, 187], [139, 163, 137, 115, 116, 162, 114, 94, 95, 96, 97, 98, 113, 117, 136, 140, 161, 186, 187], [140, 138, 116, 117, 163, 115, 95, 96, 97, 98, 99, 114, 118, 137, 141, 162, 187], [141, 139, 117, 118, 116, 96, 97, 98, 99, 100, 115, 119, 138, 163], [140, 118, 119, 117, 97, 98, 99, 100, 101, 116, 120, 139], [143, 167, 168, 166, 144, 165, 169, 193, 194, 195, 196, 197], [144, 168, 142, 169, 167, 145, 166, 170, 194, 195, 196, 197, 198], [145, 169, 143, 170, 168, 121, 142, 146, 167, 171, 195, 196, 197, 198, 199], [146, 170, 144, 121, 171, 169, 122, 143, 147, 168, 172, 196, 197, 198, 199, 200], [147, 171, 145, 121, 122, 172, 170, 123, 144, 148, 169, 173, 197, 198, 199, 200, 201], [148, 172, 146, 122, 123, 173, 171, 121, 124, 145, 149, 170, 174, 198, 199, 200, 201, 202], [149, 173, 147, 123, 124, 174, 172, 122, 121, 125, 146, 150, 171, 175, 199, 200, 201, 202, 203], [150, 174, 148, 124, 125, 175, 173, 123, 103, 122, 126, 147, 151, 172, 176, 200, 201, 202, 203, 204], [151, 175, 149, 125, 126, 176, 174, 124, 103, 104, 123, 127, 148, 152, 173, 177, 201, 202, 203, 204, 205], [152, 176, 150, 126, 127, 177, 175, 125, 103, 104, 105, 124, 128, 149, 153, 174, 178, 202, 203, 204, 205, 206], [153, 177, 151, 127, 128, 178, 176, 126, 103, 104, 105, 106, 125, 129, 150, 154, 175, 179, 203, 204, 205, 206, 207], [154, 178, 152, 128, 129, 179, 177, 127, 103, 104, 105, 106, 107, 126, 130, 151, 155, 176, 180, 204, 205, 206, 207, 208], [155, 179, 153, 129, 130, 180, 178, 128, 104, 105, 106, 107, 108, 127, 131, 152, 156, 177, 181, 205, 206, 207, 208, 209], [156, 180, 154, 130, 131, 181, 179, 129, 105, 106, 107, 108, 109, 128, 132, 153, 157, 178, 182, 206, 207, 208, 209, 210], [157, 181, 155, 131, 132, 182, 180, 130, 106, 107, 108, 109, 110, 129, 133, 154, 158, 179, 183, 207, 208, 209, 210, 211], [158, 182, 156, 132, 133, 183, 181, 131, 107, 108, 109, 110, 111, 130, 134, 155, 159, 180, 184, 208, 209, 210, 211, 212], [159, 183, 157, 133, 134, 184, 182, 132, 108, 109, 110, 111, 112, 131, 135, 156, 160, 181, 185, 209, 210, 211, 212, 213], [160, 184, 158, 134, 135, 185, 183, 133, 109, 110, 111, 112, 113, 132, 136, 157, 161, 182, 186, 210, 211, 212, 213], [161, 185, 159, 135, 136, 186, 184, 134, 110, 111, 112, 113, 114, 133, 137, 158, 162, 183, 187, 211, 212, 213], [162, 186, 160, 136, 137, 187, 185, 135, 111, 112, 113, 114, 115, 134, 138, 159, 163, 184, 212, 213], [163, 187, 161, 137, 138, 186, 136, 112, 113, 114, 115, 116, 135, 139, 160, 185, 213], [162, 138, 139, 187, 137, 113, 114, 115, 116, 117, 136, 140, 161, 186], [165, 192, 193, 191, 166, 190, 194, 214, 215, 216, 217], [166, 193, 164, 194, 192, 142, 167, 191, 195, 214, 215, 216, 217, 218], [167, 194, 165, 142, 195, 193, 143, 164, 168, 192, 196, 215, 216, 217, 218, 219], [168, 195, 166, 142, 143, 196, 194, 144, 165, 169, 193, 197, 216, 217, 218, 219, 220], [169, 196, 167, 143, 144, 197, 195, 142, 145, 166, 170, 194, 198, 217, 218, 219, 220, 221], [170, 197, 168, 144, 145, 198, 196, 143, 121, 142, 146, 167, 171, 195, 199, 218, 219, 220, 221, 222], [171, 198, 169, 145, 146, 199, 197, 144, 121, 122, 143, 147, 168, 172, 196, 200, 219, 220, 221, 222, 223], [172, 199, 170, 146, 147, 200, 198, 145, 121, 122, 123, 144, 148, 169, 173, 197, 201, 220, 221, 222, 223, 224], [173, 200, 171, 147, 148, 201, 199, 146, 121, 122, 123, 124, 145, 149, 170, 174, 198, 202, 221, 222, 223, 224, 225], [174, 201, 172, 148, 149, 202, 200, 147, 121, 122, 123, 124, 125, 146, 150, 171, 175, 199, 203, 222, 223, 224, 225, 226], [175, 202, 173, 149, 150, 203, 201, 148, 122, 123, 124, 125, 126, 147, 151, 172, 176, 200, 204, 223, 224, 225, 226, 227], [176, 203, 174, 150, 151, 204, 202, 149, 123, 124, 125, 126, 127, 148, 152, 173, 177, 201, 205, 224, 225, 226, 227, 228], [177, 204, 175, 151, 152, 205, 203, 150, 124, 125, 126, 127, 128, 149, 153, 174, 178, 202, 206, 225, 226, 227, 228, 229], [178, 205, 176, 152, 153, 206, 204, 151, 125, 126, 127, 128, 129, 150, 154, 175, 179, 203, 207, 226, 227, 228, 229, 230], [179, 206, 177, 153, 154, 207, 205, 152, 126, 127, 128, 129, 130, 151, 155, 176, 180, 204, 208, 227, 228, 229, 230, 231], [180, 207, 178, 154, 155, 208, 206, 153, 127, 128, 129, 130, 131, 152, 156, 177, 181, 205, 209, 228, 229, 230, 231], [181, 208, 179, 155, 156, 209, 207, 154, 128, 129, 130, 131, 132, 153, 157, 178, 182, 206, 210, 229, 230, 231], [182, 209, 180, 156, 157, 210, 208, 155, 129, 130, 131, 132, 133, 154, 158, 179, 183, 207, 211, 230, 231], [183, 210, 181, 157, 158, 211, 209, 156, 130, 131, 132, 133, 134, 155, 159, 180, 184, 208, 212, 231], [184, 211, 182, 158, 159, 212, 210, 157, 131, 132, 133, 134, 135, 156, 160, 181, 185, 209, 213], [185, 212, 183, 159, 160, 213, 211, 158, 132, 133, 134, 135, 136, 157, 161, 182, 186, 210], [186, 213, 184, 160, 161, 212, 159, 133, 134, 135, 136, 137, 158, 162, 183, 187, 211], [187, 185, 161, 162, 213, 160, 134, 135, 136, 137, 138, 159, 163, 184, 212], [186, 162, 163, 161, 135, 136, 137, 138, 139, 160, 185, 213], [189, 190], [190, 188, 191, 214], [191, 189, 214, 164, 188, 192, 215, 232], [192, 214, 190, 164, 215, 165, 189, 193, 216, 232, 233], [193, 215, 191, 164, 165, 216, 214, 166, 190, 194, 217, 232, 233, 234], [194, 216, 192, 165, 166, 217, 215, 164, 142, 167, 191, 195, 214, 218, 232, 233, 234, 235], [195, 217, 193, 166, 167, 218, 216, 165, 142, 143, 164, 168, 192, 196, 215, 219, 232, 233, 234, 235, 236], [196, 218, 194, 167, 168, 219, 217, 166, 142, 143, 144, 165, 169, 193, 197, 216, 220, 233, 234, 235, 236, 237], [197, 219, 195, 168, 169, 220, 218, 167, 142, 143, 144, 145, 166, 170, 194, 198, 217, 221, 234, 235, 236, 237, 238], [198, 220, 196, 169, 170, 221, 219, 168, 142, 143, 144, 145, 146, 167, 171, 195, 199, 218, 222, 235, 236, 237, 238, 239], [199, 221, 197, 170, 171, 222, 220, 169, 143, 144, 145, 146, 147, 168, 172, 196, 200, 219, 223, 236, 237, 238, 239, 240], [200, 222, 198, 171, 172, 223, 221, 170, 144, 145, 146, 147, 148, 169, 173, 197, 201, 220, 224, 237, 238, 239, 240, 241], [201, 223, 199, 172, 173, 224, 222, 171, 145, 146, 147, 148, 149, 170, 174, 198, 202, 221, 225, 238, 239, 240, 241, 242], [202, 224, 200, 173, 174, 225, 223, 172, 146, 147, 148, 149, 150, 171, 175, 199, 203, 222, 226, 239, 240, 241, 242, 243], [203, 225, 201, 174, 175, 226, 224, 173, 147, 148, 149, 150, 151, 172, 176, 200, 204, 223, 227, 240, 241, 242, 243, 244], [204, 226, 202, 175, 176, 227, 225, 174, 148, 149, 150, 151, 152, 173, 177, 201, 205, 224, 228, 241, 242, 243, 244, 245], [205, 227, 203, 176, 177, 228, 226, 175, 149, 150, 151, 152, 153, 174, 178, 202, 206, 225, 229, 242, 243, 244, 245], [206, 228, 204, 177, 178, 229, 227, 176, 150, 151, 152, 153, 154, 175, 179, 203, 207, 226, 230, 243, 244, 245], [207, 229, 205, 178, 179, 230, 228, 177, 151, 152, 153, 154, 155, 176, 180, 204, 208, 227, 231, 244, 245], [208, 230, 206, 179, 180, 231, 229, 178, 152, 153, 154, 155, 156, 177, 181, 205, 209, 228, 245], [209, 231, 207, 180, 181, 230, 179, 153, 154, 155, 156, 157, 178, 182, 206, 210, 229], [210, 208, 181, 182, 231, 180, 154, 155, 156, 157, 158, 179, 183, 207, 211, 230], [211, 209, 182, 183, 181, 155, 156, 157, 158, 159, 180, 184, 208, 212, 231], [212, 210, 183, 184, 182, 156, 157, 158, 159, 160, 181, 185, 209, 213], [213, 211, 184, 185, 183, 157, 158, 159, 160, 161, 182, 186, 210], [212, 185, 186, 184, 158, 159, 160, 161, 162, 183, 187, 211], [215, 191, 192, 232, 190, 164, 165, 189, 193, 216, 233], [216, 232, 214, 192, 193, 233, 191, 164, 165, 166, 190, 194, 217, 234, 246], [217, 233, 215, 193, 194, 234, 232, 192, 164, 165, 166, 167, 191, 195, 214, 218, 235, 246, 247], [218, 234, 216, 194, 195, 235, 233, 193, 164, 165, 166, 167, 168, 192, 196, 215, 219, 232, 236, 246, 247, 248], [219, 235, 217, 195, 196, 236, 234, 194, 165, 166, 167, 168, 169, 193, 197, 216, 220, 233, 237, 246, 247, 248, 249], [220, 236, 218, 196, 197, 237, 235, 195, 166, 167, 168, 169, 170, 194, 198, 217, 221, 234, 238, 246, 247, 248, 249, 250], [221, 237, 219, 197, 198, 238, 236, 196, 167, 168, 169, 170, 171, 195, 199, 218, 222, 235, 239, 247, 248, 249, 250, 251], [222, 238, 220, 198, 199, 239, 237, 197, 168, 169, 170, 171, 172, 196, 200, 219, 223, 236, 240, 248, 249, 250, 251, 252], [223, 239, 221, 199, 200, 240, 238, 198, 169, 170, 171, 172, 173, 197, 201, 220, 224, 237, 241, 249, 250, 251, 252, 253], [224, 240, 222, 200, 201, 241, 239, 199, 170, 171, 172, 173, 174, 198, 202, 221, 225, 238, 242, 250, 251, 252, 253, 254], [225, 241, 223, 201, 202, 242, 240, 200, 171, 172, 173, 174, 175, 199, 203, 222, 226, 239, 243, 251, 252, 253, 254, 255], [226, 242, 224, 202, 203, 243, 241, 201, 172, 173, 174, 175, 176, 200, 204, 223, 227, 240, 244, 252, 253, 254, 255], [227, 243, 225, 203, 204, 244, 242, 202, 173, 174, 175, 176, 177, 201, 205, 224, 228, 241, 245, 253, 254, 255], [228, 244, 226, 204, 205, 245, 243, 203, 174, 175, 176, 177, 178, 202, 206, 225, 229, 242, 254, 255], [229, 245, 227, 205, 206, 244, 204, 175, 176, 177, 178, 179, 203, 207, 226, 230, 243, 255], [230, 228, 206, 207, 245, 205, 176, 177, 178, 179, 180, 204, 208, 227, 231, 244], [231, 229, 207, 208, 206, 177, 178, 179, 180, 181, 205, 209, 228, 245], [230, 208, 209, 207, 178, 179, 180, 181, 182, 206, 210, 229], [233, 215, 216, 214, 190, 191, 192, 193, 194, 217, 234, 246], [234, 232, 216, 217, 246, 215, 191, 192, 193, 194, 195, 214, 218, 235, 247, 256], [235, 246, 233, 217, 218, 247, 216, 192, 193, 194, 195, 196, 215, 219, 232, 236, 248, 256, 257], [236, 247, 234, 218, 219, 248, 246, 217, 193, 194, 195, 196, 197, 216, 220, 233, 237, 249, 256, 257, 258], [237, 248, 235, 219, 220, 249, 247, 218, 194, 195, 196, 197, 198, 217, 221, 234, 238, 246, 250, 256, 257, 258, 259], [238, 249, 236, 220, 221, 250, 248, 219, 195, 196, 197, 198, 199, 218, 222, 235, 239, 247, 251, 256, 257, 258, 259, 260], [239, 250, 237, 221, 222, 251, 249, 220, 196, 197, 198, 199, 200, 219, 223, 236, 240, 248, 252, 257, 258, 259, 260, 261], [240, 251, 238, 222, 223, 252, 250, 221, 197, 198, 199, 200, 201, 220, 224, 237, 241, 249, 253, 258, 259, 260, 261, 262], [241, 252, 239, 223, 224, 253, 251, 222, 198, 199, 200, 201, 202, 221, 225, 238, 242, 250, 254, 259, 260, 261, 262], [242, 253, 240, 224, 225, 254, 252, 223, 199, 200, 201, 202, 203, 222, 226, 239, 243, 251, 255, 260, 261, 262], [243, 254, 241, 225, 226, 255, 253, 224, 200, 201, 202, 203, 204, 223, 227, 240, 244, 252, 261, 262], [244, 255, 242, 226, 227, 254, 225, 201, 202, 203, 204, 205, 224, 228, 241, 245, 253, 262], [245, 243, 227, 228, 255, 226, 202, 203, 204, 205, 206, 225, 229, 242, 254], [244, 228, 229, 227, 203, 204, 205, 206, 207, 226, 230, 243, 255], [247, 234, 235, 256, 233, 215, 216, 217, 218, 219, 232, 236, 248, 257, 263], [248, 256, 246, 235, 236, 257, 234, 216, 217, 218, 219, 220, 233, 237, 249, 258, 263, 264], [249, 257, 247, 236, 237, 258, 256, 235, 217, 218, 219, 220, 221, 234, 238, 246, 250, 259, 263, 264, 265], [250, 258, 248, 237, 238, 259, 257, 236, 218, 219, 220, 221, 222, 235, 239, 247, 251, 256, 260, 263, 264, 265, 266], [251, 259, 249, 238, 239, 260, 258, 237, 219, 220, 221, 222, 223, 236, 240, 248, 252, 257, 261, 263, 264, 265, 266], [252, 260, 250, 239, 240, 261, 259, 238, 220, 221, 222, 223, 224, 237, 241, 249, 253, 258, 262, 264, 265, 266], [253, 261, 251, 240, 241, 262, 260, 239, 221, 222, 223, 224, 225, 238, 242, 250, 254, 259, 265, 266], [254, 262, 252, 241, 242, 261, 240, 222, 223, 224, 225, 226, 239, 243, 251, 255, 260, 266], [255, 253, 242, 243, 262, 241, 223, 224, 225, 226, 227, 240, 244, 252, 261], [254, 243, 244, 242, 224, 225, 226, 227, 228, 241, 245, 253, 262], [257, 247, 248, 263, 246, 233, 234, 235, 236, 237, 249, 258, 264], [258, 263, 256, 248, 249, 264, 247, 234, 235, 236, 237, 238, 246, 250, 259, 265], [259, 264, 257, 249, 250, 265, 263, 248, 235, 236, 237, 238, 239, 247, 251, 256, 260, 266], [260, 265, 258, 250, 251, 266, 264, 249, 236, 237, 238, 239, 240, 248, 252, 257, 261, 263], [261, 266, 259, 251, 252, 265, 250, 237, 238, 239, 240, 241, 249, 253, 258, 262, 264], [262, 260, 252, 253, 266, 251, 238, 239, 240, 241, 242, 250, 254, 259, 265], [261, 253, 254, 252, 239, 240, 241, 242, 243, 251, 255, 260, 266], [264, 257, 258, 256, 246, 247, 248, 249, 250, 259, 265], [265, 263, 258, 259, 257, 247, 248, 249, 250, 251, 256, 260, 266], [266, 264, 259, 260, 258, 248, 249, 250, 251, 252, 257, 261, 263], [265, 260, 261, 259, 249, 250, 251, 252, 253, 258, 262, 264]]
Column_Numbers2 = list(np.arange(1,TotalNumbcol+1,1))
Chosen_Columns2 = []
# shuffle(Column_Numbers2) <--- This line was very slow.
Column_Numbers2 = np.random.permutation(Column_Numbers2).tolist()
rand = Column_Numbers2.pop()
Chosen_Columns2.append(rand)
while Column_Numbers2:
for i in range(rand-1,rand):
rand = NeighborsperColumn[i]
rand = [x for x in rand if x not in Chosen_Columns2]
shuffle(rand)
try:
rand = rand.pop()
Chosen_Columns2.append(rand)
Column_Numbers2.remove(rand)
except IndexError:
rand = Column_Numbers2.pop()
Chosen_Columns2.append(rand)
END_CLOCK = datetime.now()
DELTA_TIME = END_CLOCK - START_CLOCK
print DELTA_TIME
In general you should use a profiler to find the lines in your code that are too slow.

Related

extract index of element in list python

I have a list named 'partition'
[array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29]), array([214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226,
227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239,
240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250]), array([251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263,
264, 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, 276]), array([277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288, 289,
290, 291, 292, 293, 294, 295, 296, 297, 298, 299, 300, 301, 302,
303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314]), array([30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46,
47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
64, 65, 66, 67, 68, 69, 70]), array([ 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83,
84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96,
97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109,
110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121]), array([122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134,
135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147,
148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160,
161, 162, 163, 164]), array([165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177,
178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190,
191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203,
204, 205, 206, 207, 208, 209, 210, 211, 212, 213])]
And i try to extract the index of an element (1 for example) with this code:
a= partition.index(1)
But i get this error :
ValueError Traceback (most recent call last)
/tmp/ipykernel_582922/1287398992.py in <module>
----> 1 a= partition.index(1)
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
Can you help me please to fix this error?
Kind regards
This should solve the problem:
import numpy as np
from numpy import array
partition = array([array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29]), array([214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226,
227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239,
240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250]), array([251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263,
264, 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, 276]), array([277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288, 289,
290, 291, 292, 293, 294, 295, 296, 297, 298, 299, 300, 301, 302,
303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314]), array([30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46,
47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
64, 65, 66, 67, 68, 69, 70]), array([ 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83,
84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96,
97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109,
110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121]), array([122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134,
135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147,
148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160,
161, 162, 163, 164]), array([165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177,
178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190,
191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203,
204, 205, 206, 207, 208, 209, 210, 211, 212, 213])], dtype="object")
result = [(i, np.where(j == 1)[0]) for i, j in enumerate(partition) if np.any(np.where(j == 1))]
print(result)
The result will be in the format of (This is an example):
[(*the index of the array*, *an array with all indexes of the elements that are 1*), (*the index of the array*, *an array with all indexes of the elements that are 1*)]
I'm not sure if this is the best way to do it though.
Or if you have a list of numpy arrays you could do something like this:
from numpy import array
partition = [array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29]), array([214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226,
227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239,
240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250]), array([251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263,
264, 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, 276]), array([277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288, 289,
290, 291, 292, 293, 294, 295, 296, 297, 298, 299, 300, 301, 302,
303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314]), array([30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46,
47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
64, 65, 66, 67, 68, 69, 70]), array([ 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83,
84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96,
97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109,
110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121]), array([122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134,
135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147,
148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160,
161, 162, 163, 164]), array([165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177,
178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190,
191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203,
204, 205, 206, 207, 208, 209, 210, 211, 212, 213])]
result = []
for i, j in enumerate(partition):
for l in j:
if l == 1:
result.append((i, l))
print(result)

Python : Creating raw ECC-ECDSA-SECP256R1 private(32-bytes) and public(64-bytes) keys

I want to generate raw 32-bytes private key and raw 64-bytes public key (ECC-SECP256R1) using Python.
Which library should I install in my Python 3.7 and what APIs do I call to be able to generate raw keys?
Please help.
TIA.
The ECDSA library can do this.
Generate a key pair:
import ecdsa
sk = ecdsa.SigningKey.generate(curve=ecdsa.SECP256k1)
vk = sk.get_verifying_key()
# Your byte values will vary, each time you generate(). Here is an example pair.
skBytes = sk.to_string()
print(f"Signing key = {[b for b in skBytes]}")
# [242, 122, 66, 46, 189, 185, 103, 40, 162, 156, 155, 213, 77, 38, 251, 23, 148, 207, 49, 206, 122, 63, 117, 150, 196, 115, 82, 203, 95, 104, 60, 227]
vkBytes = vk.to_string()
print(f"Verifying key = {[b for b in vkBytes]}")
# [31, 164, 220, 214, 106, 22, 45, 112, 244, 49, 124, 250, 217, 209, 51, 83, 161, 239, 137, 124, 25, 220, 112, 116, 80, 9, 64, 130, 9, 27, 92, 198, 123, 146, 213, 154, 142, 148, 90, 6, 142, 177, 31, 151, 215, 9, 216, 36, 51, 27, 222, 224, 132, 7, 39, 227, 48, 31, 244, 218, 206, 59, 249, 196]
The key pair can be restored from bytes:
skBytes = bytes([242, 122, 66, 46, 189, 185, 103, 40, 162, 156, 155, 213, 77, 38, 251, 23, 148, 207, 49, 206, 122, 63, 117, 150, 196, 115, 82, 203, 95, 104, 60, 227])
vkBytes = bytes([31, 164, 220, 214, 106, 22, 45, 112, 244, 49, 124, 250, 217, 209, 51, 83, 161, 239, 137, 124, 25, 220, 112, 116, 80, 9, 64, 130, 9, 27, 92, 198, 123, 146, 213, 154, 142, 148, 90, 6, 142, 177, 31, 151, 215, 9, 216, 36, 51, 27, 222, 224, 132, 7, 39, 227, 48, 31, 244, 218, 206, 59, 249, 196])
sk = ecdsa.SigningKey.from_string(skBytes, curve=ecdsa.SECP256k1)
vk = ecdsa.VerifyingKey.from_string(vkBytes, curve=ecdsa.SECP256k1)
# or vk = sk.get_verifying_key()
Example signing and verifying:
message = b"Hello, world!"
signature = sk.sign(message)
print(f"{[b for b in signature]}")
# [161, 22, 110, 48, 232, 36, 152, 153, 22, 7, 177, 219, 157, 102, 237, 57, 243, 216, 186, 207, 22, 168, 170, 247, 216, 235, 160, 13, 35, 37, 141, 237, 63, 50, 84, 31, 203, 95, 212, 91, 13, 150, 156, 125, 255, 197, 30, 133, 193, 174, 129, 174, 192, 33, 90, 160, 243, 78, 96, 92, 38, 1, 237, 129]
isSignatureValid = vk.verify(signature, message)
print(f"{isSignatureValid=}")
# isSignatureValid=True
Credit to this question for introducing me to the ecdsa package:
ECDSA Signing and Verifying issue between python ECDSA and C micro-ecc library

What is the best way to calculate the standard deviation

I have a 50x22 matrix/vector, and i need to calculate the standard deviation from each column, precisely it looks like this.
For instance, the first column: [245, 244, 247, 243... 239], then second column [115, 106, 99...149] and on...
I did try calculating it using a calculator, i guess it wasn't a good idea, it took me a while, but i figured numpy could help me.
The thing is, what i tried was:
std_vec = np.std(img_feats[0])
The output was all wrong, when i compared to the firt column that i obtained using the calculator.
This is the actual output, since the image picture does not look good.
[247, 111, 162, 47, 39, 42, 47, 42, 204, 215, 50, 57, 196, 209, 199, 184, 219, 201, 204, 218]
[247, 108, 160, 47, 39, 44, 48, 44, 204, 213, 51, 60, 198, 205, 201, 184, 219, 201, 202, 216]
[245, 96, 160, 46, 38, 43, 44, 40, 195, 213, 51, 57, 199, 202, 204, 187, 222, 201, 202, 207]
[245, 102, 161, 46, 40, 41, 46, 40, 198, 213, 51, 55, 199, 210, 202, 187, 220, 202, 204, 210]
[246, 104, 160, 49, 38, 41, 46, 41, 198, 214, 52, 55, 199, 210, 204, 185, 220, 204, 204, 208]
[246, 107, 160, 47, 40, 40, 46, 40, 196, 213, 51, 57, 199, 207, 201, 185, 220, 202, 205, 208]
[246, 116, 161, 48, 40, 43, 45, 41, 201, 213, 51, 58, 201, 201, 204, 184, 219, 204, 205, 210]
[246, 123, 169, 48, 40, 42, 46, 43, 202, 213, 51, 64, 199, 198, 201, 189, 217, 199, 207, 216]
[246, 123, 167, 48, 40, 40, 45, 43, 204, 213, 51, 67, 198, 199, 202, 187, 219, 199, 207, 214]
[246, 122, 167, 48, 40, 43, 46, 43, 202, 213, 51, 64, 199, 197, 200, 185, 219, 199, 208, 213]
[245, 115, 165, 47, 38, 43, 44, 43, 199, 213, 51, 58, 199, 191, 203, 187, 217, 194, 206, 208]
[244, 106, 162, 47, 40, 40, 43, 40, 194, 214, 49, 58, 199, 188, 205, 191, 216, 199, 203, 208]
[247, 99, 160, 46, 42, 40, 46, 42, 201, 213, 51, 55, 198, 204, 201, 185, 220, 199, 202, 216]
[243, 98, 161, 47, 41, 43, 43, 40, 193, 214, 50, 58, 199, 191, 207, 190, 214, 197, 205, 207]
[242, 96, 159, 46, 40, 41, 44, 43, 188, 214, 50, 56, 200, 197, 208, 190, 214, 197, 205, 205]
[243, 99, 164, 47, 40, 41, 44, 41, 189, 213, 49, 55, 201, 198, 208, 192, 215, 198, 204, 205]
[245, 105, 166, 49, 40, 41, 44, 40, 193, 215, 49, 56, 199, 202, 207, 192, 218, 201, 207, 208]
[246, 112, 167, 46, 40, 44, 44, 43, 195, 211, 50, 60, 198, 204, 205, 190, 218, 201, 205, 210]
[245, 112, 166, 47, 40, 43, 44, 43, 199, 214, 49, 59, 202, 205, 205, 188, 219, 201, 208, 210]
[245, 112, 165, 47, 39, 44, 46, 43, 197, 213, 50, 58, 200, 204, 205, 188, 219, 202, 208, 211]
[245, 111, 167, 45, 42, 42, 42, 41, 199, 213, 50, 59, 200, 203, 210, 187, 219, 200, 208, 211]
[245, 115, 167, 48, 41, 42, 44, 42, 199, 212, 51, 62, 200, 205, 206, 187, 219, 202, 209, 211]
[244, 122, 168, 47, 42, 41, 45, 41, 199, 212, 51, 63, 200, 203, 206, 185, 219, 200, 208, 212]
[247, 99, 160, 45, 40, 42, 48, 43, 200, 211, 51, 55, 197, 202, 199, 184, 220, 199, 204, 214]
[244, 121, 168, 50, 39, 42, 43, 40, 202, 211, 50, 63, 200, 199, 208, 183, 220, 203, 208, 212]
[245, 121, 167, 50, 40, 42, 43, 40, 200, 212, 50, 63, 202, 197, 208, 186, 220, 203, 208, 215]
[245, 119, 165, 48, 40, 42, 45, 42, 199, 212, 50, 62, 202, 194, 206, 186, 218, 200, 209, 211]
[245, 124, 165, 47, 37, 42, 45, 40, 202, 211, 50, 63, 202, 194, 206, 185, 217, 199, 209, 215]
[244, 129, 168, 47, 39, 40, 45, 42, 208, 209, 50, 71, 202, 197, 206, 187, 214, 199, 209, 215]
[244, 134, 173, 50, 39, 42, 45, 42, 208, 209, 51, 80, 202, 199, 206, 189, 209, 199, 208, 217]
[243, 140, 176, 54, 39, 40, 45, 40, 209, 211, 50, 83, 205, 201, 208, 189, 205, 198, 212, 220]
[242, 142, 177, 65, 39, 42, 44, 40, 215, 212, 50, 97, 201, 203, 206, 189, 203, 200, 211, 220]
[241, 147, 182, 74, 39, 42, 44, 41, 212, 214, 51, 106, 204, 203, 209, 191, 200, 195, 209, 221]
[241, 151, 182, 78, 39, 39, 45, 42, 212, 214, 51, 108, 206, 203, 206, 192, 197, 194, 206, 220]
[246, 99, 159, 46, 38, 41, 46, 41, 197, 213, 50, 54, 199, 203, 202, 182, 222, 197, 200, 213]
[239, 151, 183, 81, 37, 42, 45, 40, 212, 211, 50, 112, 206, 203, 206, 191, 194, 197, 209, 220]
[238, 149, 185, 78, 41, 41, 47, 41, 211, 211, 51, 111, 207, 204, 206, 192, 192, 195, 207, 220]
[238, 147, 182, 74, 39, 39, 45, 44, 211, 211, 51, 107, 209, 206, 207, 192, 195, 194, 207, 221]
[241, 146, 183, 73, 39, 41, 45, 44, 212, 211, 51, 107, 208, 206, 206, 191, 197, 195, 209, 221]
[237, 147, 182, 80, 41, 41, 45, 44, 210, 212, 51, 108, 209, 209, 209, 195, 195, 197, 210, 221]
[240, 150, 183, 85, 41, 42, 45, 42, 210, 213, 53, 112, 210, 207, 209, 194, 197, 195, 209, 220]
[241, 150, 180, 83, 36, 44, 45, 40, 210, 213, 51, 112, 207, 204, 207, 192, 195, 192, 207, 219]
[239, 149, 180, 83, 42, 42, 46, 42, 210, 213, 51, 109, 209, 204, 209, 192, 198, 190, 209, 221]
[239, 149, 183, 84, 40, 42, 46, 40, 208, 213, 51, 111, 210, 204, 208, 192, 198, 187, 208, 219]
[238, 151, 184, 87, 40, 42, 43, 43, 208, 213, 51, 113, 213, 205, 208, 190, 195, 190, 208, 220]
[246, 99, 158, 44, 38, 40, 44, 41, 196, 213, 54, 55, 199, 205, 200, 182, 220, 196, 200, 213]
[246, 98, 156, 46, 40, 41, 47, 44, 197, 214, 51, 55, 199, 210, 202, 184, 220, 196, 199, 211]
[245, 96, 158, 44, 40, 41, 46, 43, 194, 213, 54, 55, 202, 205, 202, 187, 220, 199, 202, 210]
[244, 92, 157, 44, 38, 40, 46, 41, 191, 213, 51, 54, 199, 205, 205, 187, 219, 198, 202, 208]
[244, 92, 157, 46, 38, 40, 44, 44, 191, 213, 51, 54, 198, 205, 207, 188, 219, 199, 202, 208]
These results are comming from features extracted from my images, not sure if its relevant though, but here's my actual code:
for img1 in imgs1:
img_feats = []
for coords in coord_list:
std_vec = np.std(img_feats[0])
img_feats.append(img1[coords[0], coords[1]]) # extracts the features that composes my matrix
print(img_feats)
The output should look like this [1.879 3.0284 5.9333 2.0156 2.2467 2.0092 4.7983 4.3554 3.6372 1.3159 2.6174 2.2336 0.9625 5.6285 5.4040 2.7887 0 3.4632 0 2.7370]
Like most numpy functions, the std function has an axis parameter. np.std(img_feats, axis=0) will return the standard deviation of each column. axis=1 will give the standard deviation across of each row.
In your example this would read:
feat_vec_1 = []
for img1 in imgs1:
img_feats = []
for coords in coord_list:
img_feats.append(img1[coords[0], coords[1]])
feat_vec_1.append(img_feats)
std_colomns = np.std(feat_vec_1, axis=0)
I am not sure what you are really asking, but if your array is foo, then
np.std(foo, axis=0)
Will compute the standard deviations of all the columns.
for img1 in imgs1:
img_feats = []
for coords in coord_list:
std_vec = np.std(img_feats[0])
img_feats.append(img1[coords[0], coords[1]])
feat_vec_1.append(img_feats)
print(img_feats)
I don't get this actually, maybe you should calculate the deviation after you built the whole matrix? And the column you get with img_feats[0,:] if it is a numpy array

How to find differences of mat files in Python in human readable format?

.mat files can be loaded into Python with:
import scipy.io
matdata1 = scipy.io.loadmat('file1.mat')
matdata2 = scipy.io.loadmat('file2.mat')
the files can then be piped and save the mat files as text by calling the following Python function:
def mat2txt(matdata):
for k, v in matdata.items(): #Python 3 specific
if isinstance(v,dict):
myprint(v)
else:
print (k,v)
The two .mat files that are being compared are of the same structure and type with different values.
I would like to able to identify the different values in human readable format, and not just their location.
I have tried:
diff matdata1.txt matdata2.txt
diff matdata1.txt matdata2.txt | grep "<" | sed 's/^<//g'
grep -v -F -x -f matdata1.txt matdata2.txt
which do not point to specific differences in values, and they are not within Python. I hoped to store the .mat files as .txt to be able to create a static state to compare the files data at different dates relative to itself and other files, as well as, affording the opportunity to store in git for future comparisons.
A toy example of the resulting data files are:
matdata1.txt
b [[([[(array([[0]], dtype=uint8),)]],)]]
a [[([[(array([[0]], dtype=uint8),)]],)]]
c [[ ([[(array([[ ([[122, 139, 156, 173, 190, 207, 224, 1, 18, 35, 52, 69, 86, 103, 120], [138, 155, 172, 189, 206, 223, 15, 17, 34, 51, 68, 85, 102, 119, 121], [154, 171, 188, 205, 222, 14, 16, 33, 50, 67, 84, 101, 118, 135, 137], [170, 187, 204, 221, 13, 30, 32, 49, 66, 83, 100, 117, 134, 136, 153], [186, 203, 220, 12, 29, 31, 48, 65, 82, 99, 116, 133, 150, 152, 169], [202, 22, 11, 28, 45, 47, 64, 81, 98, 115, 132, 149, 151, 168, 185], [218, 10, 27, 33, 46, 63, 80, 97, 114, 131, 148, 165, 167, 184, 201], [9, 26, 43, 60, 62, 11, 96, 113, 130, 147, 164, 166, 183, 200, 217], [25, 42, 59, 61, 78, 95, 112, 99, 146, 163, 180, 182, 199, 216, 8], [41, 58, 75, 77, 94, 111, 128, 145, 162, 179, 181, 198, 215, 7, 24], [57, 74, 76, 93, 110, 127, 144, 161, 178, 195, 197, 214, 6, 23, 40], [73, 90, 92, 109, 126, 143, 160, 177, 194, 196, 213, 5, 22, 39, 56], [89, 91, 108, 125, 142, 159, 176, 193, 210, 212, 4, 21, 38, 55, 72], [105, 107, 124, 141, 158, 175, 192, 209, 211, 3, 20, 37, 54, 71, 88], [106, 123, 140, 157, 174, 191, 208, 225, 2, 19, 36, 53, 70, 87, 104]],)]],
dtype=[('c', 'O')]),)]],)]]
__header__ b'MATLAB 5.0 MAT-file, Platform: PCWIN64, Created on: Mon Jun 27 20:55:29 2016'
d [[1]]
__globals__ []
f ['string']
__version__ 1.0
e [[2]]
matdata2.txt
e [[2]]
d [[1]]
__globals__ []
f ['string']
__header__ b'MATLAB 5.0 MAT-file, Platform: PCWIN64, Created on: Mon Jun 27 20:54:48 2016'
c [[ ([[(array([[ ([[122, 139, 156, 173, 190, 207, 224, 1, 18, 35, 52, 69, 86, 103, 120], [138, 155, 172, 189, 206, 223, 15, 17, 34, 51, 68, 85, 102, 119, 121], [154, 171, 188, 205, 222, 14, 16, 33, 50, 67, 84, 101, 118, 135, 137], [170, 187, 204, 221, 13, 30, 32, 49, 66, 83, 100, 117, 134, 136, 153], [186, 203, 220, 12, 29, 31, 48, 65, 82, 99, 116, 133, 150, 152, 169], [202, 219, 11, 28, 45, 47, 64, 81, 98, 115, 132, 149, 151, 168, 185], [218, 10, 27, 44, 46, 63, 80, 97, 114, 131, 148, 165, 167, 184, 201], [9, 26, 43, 60, 62, 79, 96, 113, 130, 147, 164, 166, 183, 200, 217], [25, 42, 59, 61, 78, 95, 112, 129, 146, 163, 180, 182, 199, 216, 8], [41, 58, 75, 77, 94, 111, 128, 145, 162, 179, 181, 198, 215, 7, 24], [57, 74, 76, 93, 110, 127, 144, 161, 178, 195, 197, 214, 6, 23, 40], [73, 90, 92, 109, 126, 143, 160, 177, 194, 196, 213, 5, 22, 39, 56], [89, 91, 108, 125, 142, 159, 176, 193, 210, 212, 4, 21, 38, 55, 72], [105, 107, 124, 141, 158, 175, 192, 209, 211, 3, 20, 37, 54, 71, 88], [106, 123, 140, 157, 174, 191, 208, 225, 2, 19, 36, 53, 70, 87, 104]],)]],
dtype=[('c', 'O')]),)]],)]]
a [[([[(array([[1]], dtype=uint8),)]],)]]
b [[([[(array([[0]], dtype=uint8),)]],)]]
__version__ 1.0

image analysis : separating intersecting spaghettis

I've got an image which to the human eye clearly contains several (2 here) overlapping 'laces'.
This stems from a pretty lengthy image analysis of an experiment.
The red dots are all the points contained in two vectors, px and py, one with the x_position of the red pixels, the other one with the y positions.
px= array([ 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1,
2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3,
3, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5,
5, 5, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7,
7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9,
9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10,
11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12,
13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14,
15, 15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16,
16, 16, 16, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18,
18, 18, 18, 19, 19, 19, 19, 19, 19, 19, 20, 20, 20,
20, 20, 20, 20, 21, 21, 21, 21, 21, 21, 21, 22, 22,
22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23,
24, 24, 24, 24, 24, 24, 24, 24, 25, 25, 25, 25, 25,
25, 25, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27,
27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29,
29, 29, 29, 29, 30, 30, 30, 30, 30, 30, 30, 30, 31,
31, 31, 31, 31, 31, 31, 31, 32, 32, 32, 32, 32, 32,
32, 33, 33, 33, 33, 33, 33, 33, 34, 34, 34, 34, 34,
34, 34, 35, 35, 35, 35, 35, 35, 35, 36, 36, 36, 36,
36, 36, 37, 37, 37, 37, 37, 37, 37, 38, 38, 38, 38,
38, 38, 38, 39, 39, 39, 39, 39, 39, 39, 40, 40, 40,
40, 40, 40, 40, 41, 41, 41, 41, 41, 41, 41, 41, 42,
42, 42, 42, 42, 42, 42, 43, 43, 43, 43, 43, 43, 43,
44, 44, 44, 44, 44, 44, 44, 44, 45, 45, 45, 45, 45,
45, 45, 45, 45, 45, 45, 46, 46, 46, 46, 46, 46, 46,
46, 46, 46, 46, 46, 46, 46, 46, 47, 47, 47, 47, 47,
47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 48, 48,
48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48,
48, 48, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49,
49, 49, 49, 49, 49, 49, 49, 50, 50, 50, 50, 50, 50,
50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
50, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51,
51, 51, 51, 51, 51, 51, 51, 52, 52, 52, 52, 52, 52,
52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52,
52, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53,
53, 53, 53, 53, 53, 53, 53, 53, 54, 54, 54, 54, 54,
54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54,
54, 54, 54, 54, 55, 55, 55, 55, 55, 55, 55, 55, 55,
55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55,
55, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57,
57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 58, 58, 58,
58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58,
58, 58, 58, 58, 58, 58, 59, 59, 59, 59, 59, 59, 59,
59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59,
59, 59, 59, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60,
60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60,
61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61,
61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 62, 62, 62,
62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62,
62, 62, 62, 62, 62, 62, 62, 63, 63, 63, 63, 63, 63,
63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
63, 63, 63, 63, 63, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65,
65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 66, 66,
66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66,
66, 66, 66, 66, 66, 66, 66, 66, 67, 67, 67, 67, 67,
67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67,
67, 67, 67, 67, 67, 67, 68, 68, 68, 68, 68, 68, 68,
68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68,
68, 68, 68, 68, 68, 69, 69, 69, 69, 69, 69, 69, 69,
69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69,
69, 69, 69, 69, 70, 70, 70, 70, 70, 70, 70, 70, 70,
70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70,
71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71,
71, 71, 71, 71, 71, 72, 72, 72, 72, 72, 72, 72, 72,
72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 73, 73, 73,
73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73,
73, 73, 73, 73, 74, 74, 74, 74, 74, 74, 74, 74, 74,
74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 75,
75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75,
75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 76, 76, 76,
76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76,
76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76,
77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,
77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,
77, 77, 77, 77, 77, 77, 77, 77, 78, 78, 78, 78, 78,
78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78,
78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78,
78, 78, 78, 78, 79, 79, 79, 79, 79, 79, 79, 79, 79,
79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79,
79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79,
79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79,
79, 79, 79, 79, 80, 80, 80, 80, 80, 80, 80, 80, 80,
80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80,
80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80,
80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80,
80, 80, 80, 80, 80, 80, 81, 81, 81, 81, 81, 81, 81,
81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81,
81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81,
81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81,
81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81,
81, 81, 82, 82, 82, 82, 82, 82, 82, 82, 82, 82, 82,
82, 82, 82, 82, 82, 82, 82, 82, 82, 82, 82, 82, 82,
82, 82, 82, 82, 82, 82, 82, 82, 82, 82, 82, 82, 82,
82, 82, 82, 82, 82, 82, 82, 82, 82, 82, 82, 82, 82,
82, 82, 82, 82, 82, 82, 82, 82, 83, 83, 83, 83, 83,
83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83,
83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83,
83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83,
83, 83, 83, 83, 83, 83, 83, 83, 83, 84, 84, 84, 84,
84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84,
84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84,
84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84,
84, 84, 84, 84, 85, 85, 85, 85, 85, 85, 85, 85, 85,
85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85,
85, 85, 85, 85, 86, 86, 86, 86, 86, 86, 86, 86, 86,
86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 87, 87,
87, 87, 87, 87, 88, 88, 88, 88, 88, 88, 89, 89, 89,
89, 89, 89, 89, 90, 90, 90, 90, 90, 90, 91, 91, 91,
91, 91, 91, 91, 92, 92, 92, 92, 92, 92, 92, 93, 93,
93, 93, 93, 93, 93, 94, 94, 94, 94, 94, 94, 95, 95,
95, 95, 95, 95, 96, 96, 96, 96, 96, 96, 97, 97, 97,
97, 97, 97, 97, 98, 98, 98, 98, 98, 98, 99, 99, 99,
99, 99, 99, 100, 100, 100, 100, 100, 100, 101, 101, 101, 101,
101, 101, 102, 102, 102, 102, 102, 102, 103, 103, 103, 103, 103,
103, 104, 104, 104, 104, 104, 104, 105, 105, 105, 105, 105, 105,
106, 106, 106, 106, 106, 106, 106, 107, 107, 107, 107, 107, 107,
108, 108, 108, 108, 108, 108, 108, 109, 109, 109, 109, 109, 109,
110, 110, 110, 110, 110, 110, 110, 111, 111, 111, 111, 111, 111,
112, 112, 112, 112, 112, 112, 113, 113, 113, 113, 113, 113, 114,
114, 114, 114, 114, 114, 115, 115, 115, 115, 115, 115, 116, 116,
116, 116, 116, 116, 117, 117, 117, 117, 117, 117, 117, 118, 118,
118, 118, 118, 118, 119, 119, 119, 119, 119, 119, 119, 120, 120,
120, 120, 120, 120, 121, 121, 121, 121, 121, 121, 121, 122, 122,
122, 122, 122, 122, 123, 123, 123, 123, 123, 123, 123, 124, 124,
124, 124, 124, 124, 125, 125, 125, 125, 125, 125, 125, 126, 126,
126, 126, 126, 126, 127, 127, 127, 127, 127, 127, 128, 128, 128,
128, 128, 128, 129, 129, 129, 129, 129, 129, 129, 130, 130, 130,
130, 130, 130, 131, 131, 131, 131, 131, 131, 131, 132, 132, 132,
132, 132, 132, 133, 133, 133, 133, 133, 133, 133, 134, 134, 134,
134, 134, 134, 135, 135, 135, 135, 135, 135, 135, 136, 136, 136,
136, 136, 136, 137, 137, 137, 137, 137, 137, 138, 138, 138, 138,
138, 138, 139, 139, 139, 139, 139, 139, 140, 140, 140, 140, 140,
140, 141, 141, 141, 141, 141, 141, 141, 142, 142, 142, 142, 142,
142, 143, 143, 143, 143, 143, 143, 143, 144, 144, 144, 144, 144,
144, 145, 145, 145, 145, 145, 145, 145, 146, 146, 146, 146, 146,
146, 147, 147, 147, 147, 147, 147, 148, 148, 148, 148, 148, 148,
149, 149, 149, 149, 149, 149, 150, 150, 150, 150, 150, 150, 150,
151, 151, 151, 151, 151, 151, 152, 152, 152, 152, 152, 152, 153,
153, 153, 153, 153, 153, 153, 154, 154, 154, 154, 154, 154, 155,
155, 155, 155, 155, 155, 155, 156, 156, 156, 156, 156, 156, 157,
157, 157, 157, 157, 157, 158, 158, 158, 158, 158, 158, 158, 159,
159, 159, 159, 159, 159, 159, 160, 160, 160, 160, 160, 160, 160,
161, 161, 161, 161, 161, 161, 162, 162, 162, 162, 162, 162, 162,
163, 163, 163, 163, 163, 163, 163, 164, 164, 164, 164, 164, 164,
164, 165, 165, 165, 165, 165, 165, 165, 165, 166, 166, 166, 166,
166, 166, 166, 166, 167, 167, 167, 167, 167, 167, 167, 168, 168,
168, 168, 168, 168, 168, 169, 169, 169, 169, 169, 169, 169, 170,
170, 170, 170, 170, 170, 170, 171, 171, 171, 171, 171, 171, 171,
172, 172, 172, 172, 172, 172, 172, 173, 173, 173, 173])
and
py=array([189, 190, 191, 192, 193, 194, 189, 190, 191, 192, 193, 194, 195,
190, 191, 192, 193, 194, 195, 196, 190, 191, 192, 193, 194, 195,
196, 191, 192, 193, 194, 195, 196, 197, 192, 193, 194, 195, 196,
197, 198, 193, 194, 195, 196, 197, 198, 199, 194, 195, 196, 197,
198, 199, 200, 194, 195, 196, 197, 198, 199, 200, 201, 195, 196,
197, 198, 199, 200, 201, 202, 196, 197, 198, 199, 200, 201, 202,
197, 198, 199, 200, 201, 202, 203, 198, 199, 200, 201, 202, 203,
199, 200, 201, 202, 203, 204, 199, 200, 201, 202, 203, 204, 205,
199, 200, 201, 202, 203, 204, 205, 206, 200, 201, 202, 203, 204,
205, 206, 207, 202, 203, 204, 205, 206, 207, 202, 203, 204, 205,
206, 207, 208, 203, 204, 205, 206, 207, 208, 209, 204, 205, 206,
207, 208, 209, 210, 205, 206, 207, 208, 209, 210, 211, 206, 207,
208, 209, 210, 211, 212, 206, 207, 208, 209, 210, 211, 212, 213,
207, 208, 209, 210, 211, 212, 213, 214, 208, 209, 210, 211, 212,
213, 214, 209, 210, 211, 212, 213, 214, 215, 210, 211, 212, 213,
214, 215, 216, 211, 212, 213, 214, 215, 216, 217, 211, 212, 213,
214, 215, 216, 217, 212, 213, 214, 215, 216, 217, 218, 219, 213,
214, 215, 216, 217, 218, 219, 220, 214, 215, 216, 217, 218, 219,
220, 215, 216, 217, 218, 219, 220, 221, 216, 217, 218, 219, 220,
221, 222, 217, 218, 219, 220, 221, 222, 223, 218, 219, 220, 221,
222, 223, 218, 219, 220, 221, 222, 223, 224, 219, 220, 221, 222,
223, 224, 225, 220, 221, 222, 223, 224, 225, 226, 221, 222, 223,
224, 225, 226, 227, 221, 222, 223, 224, 225, 226, 227, 228, 222,
223, 224, 225, 226, 227, 228, 223, 224, 225, 226, 227, 228, 229,
224, 225, 226, 227, 228, 229, 230, 311, 225, 226, 227, 228, 229,
230, 309, 310, 311, 312, 313, 225, 226, 227, 228, 229, 230, 231,
307, 308, 309, 310, 311, 312, 313, 314, 226, 227, 228, 229, 230,
231, 232, 306, 307, 308, 309, 310, 311, 312, 313, 314, 227, 228,
229, 230, 231, 232, 304, 305, 306, 307, 308, 309, 310, 311, 312,
313, 314, 228, 229, 230, 231, 232, 233, 302, 303, 304, 305, 306,
307, 308, 309, 310, 311, 312, 313, 228, 229, 230, 231, 232, 233,
234, 300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311,
312, 229, 230, 231, 232, 233, 234, 298, 299, 300, 301, 302, 303,
304, 305, 306, 307, 308, 309, 310, 230, 231, 232, 233, 234, 235,
296, 297, 298, 299, 300, 301, 302, 303, 304, 305, 306, 307, 308,
309, 230, 231, 232, 233, 234, 235, 236, 294, 295, 296, 297, 298,
299, 300, 301, 302, 303, 304, 305, 306, 231, 232, 233, 234, 235,
236, 237, 291, 292, 293, 294, 295, 296, 297, 298, 299, 300, 301,
302, 303, 304, 305, 232, 233, 234, 235, 236, 237, 238, 239, 288,
289, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299, 300, 301,
302, 233, 234, 235, 236, 237, 238, 239, 240, 285, 286, 287, 288,
289, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299, 300, 301,
234, 235, 236, 237, 238, 239, 240, 283, 284, 285, 286, 287, 288,
289, 290, 291, 292, 293, 294, 295, 296, 297, 298, 235, 236, 237,
238, 239, 240, 281, 282, 283, 284, 285, 286, 287, 288, 289, 290,
291, 292, 293, 294, 295, 296, 235, 236, 237, 238, 239, 240, 241,
278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288, 289, 290,
291, 292, 293, 236, 237, 238, 239, 240, 241, 242, 276, 277, 278,
279, 280, 281, 282, 283, 284, 285, 286, 287, 288, 289, 290, 291,
237, 238, 239, 240, 241, 242, 243, 273, 274, 275, 276, 277, 278,
279, 280, 281, 282, 283, 284, 285, 286, 287, 288, 238, 239, 240,
241, 242, 243, 269, 270, 271, 272, 273, 274, 275, 276, 277, 278,
279, 280, 281, 282, 283, 284, 285, 238, 239, 240, 241, 242, 243,
244, 267, 268, 269, 270, 271, 272, 273, 274, 275, 276, 277, 278,
279, 280, 281, 282, 283, 239, 240, 241, 242, 243, 244, 265, 266,
267, 268, 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, 279,
280, 240, 241, 242, 243, 244, 245, 261, 262, 263, 264, 265, 266,
267, 268, 269, 270, 271, 272, 273, 274, 275, 276, 277, 240, 241,
242, 243, 244, 245, 258, 259, 260, 261, 262, 263, 264, 265, 266,
267, 268, 269, 270, 271, 272, 273, 274, 241, 242, 243, 244, 245,
246, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266,
267, 268, 269, 270, 271, 272, 241, 242, 243, 244, 245, 246, 247,
252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264,
265, 266, 267, 268, 269, 242, 243, 244, 245, 246, 247, 249, 250,
251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263,
264, 265, 266, 267, 242, 243, 244, 245, 246, 247, 248, 249, 250,
251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263,
243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255,
256, 257, 258, 259, 260, 240, 241, 242, 243, 244, 245, 246, 247,
248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 235, 236, 237,
238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250,
251, 252, 253, 254, 231, 232, 233, 234, 235, 236, 237, 238, 239,
240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 227,
228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240,
241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 223, 224, 225,
226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238,
239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251,
215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227,
228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240,
241, 242, 246, 247, 248, 249, 250, 251, 210, 211, 212, 213, 214,
215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227,
228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 246, 247,
248, 249, 250, 251, 189, 190, 191, 192, 193, 194, 195, 196, 197,
198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210,
211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223,
224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 247, 248,
249, 250, 251, 252, 183, 184, 185, 186, 187, 188, 189, 190, 191,
192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204,
205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217,
218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230,
247, 248, 249, 250, 251, 252, 172, 173, 174, 175, 176, 177, 178,
179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191,
192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204,
205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217,
218, 219, 220, 221, 222, 223, 224, 225, 226, 248, 249, 250, 251,
252, 253, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178,
179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191,
192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204,
205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217,
218, 219, 249, 250, 251, 252, 253, 254, 167, 168, 169, 170, 171,
172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184,
185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197,
198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210,
211, 212, 213, 249, 250, 251, 252, 253, 254, 167, 168, 169, 170,
171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183,
184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196,
197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 250, 251,
252, 253, 254, 255, 167, 168, 169, 170, 171, 172, 173, 174, 175,
176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 250, 251,
252, 253, 254, 255, 168, 169, 170, 171, 172, 173, 174, 175, 176,
177, 178, 179, 180, 250, 251, 252, 253, 254, 255, 256, 251, 252,
253, 254, 255, 256, 252, 253, 254, 255, 256, 257, 252, 253, 254,
255, 256, 257, 258, 253, 254, 255, 256, 257, 258, 253, 254, 255,
256, 257, 258, 259, 254, 255, 256, 257, 258, 259, 260, 254, 255,
256, 257, 258, 259, 260, 255, 256, 257, 258, 259, 260, 256, 257,
258, 259, 260, 261, 256, 257, 258, 259, 260, 261, 256, 257, 258,
259, 260, 261, 262, 257, 258, 259, 260, 261, 262, 258, 259, 260,
261, 262, 263, 258, 259, 260, 261, 262, 263, 259, 260, 261, 262,
263, 264, 259, 260, 261, 262, 263, 264, 260, 261, 262, 263, 264,
265, 260, 261, 262, 263, 264, 265, 261, 262, 263, 264, 265, 266,
261, 262, 263, 264, 265, 266, 267, 262, 263, 264, 265, 266, 267,
262, 263, 264, 265, 266, 267, 268, 263, 264, 265, 266, 267, 268,
263, 264, 265, 266, 267, 268, 269, 264, 265, 266, 267, 268, 269,
265, 266, 267, 268, 269, 270, 265, 266, 267, 268, 269, 270, 266,
267, 268, 269, 270, 271, 266, 267, 268, 269, 270, 271, 267, 268,
269, 270, 271, 272, 267, 268, 269, 270, 271, 272, 273, 268, 269,
270, 271, 272, 273, 268, 269, 270, 271, 272, 273, 274, 269, 270,
271, 272, 273, 274, 269, 270, 271, 272, 273, 274, 275, 270, 271,
272, 273, 274, 275, 270, 271, 272, 273, 274, 275, 276, 271, 272,
273, 274, 275, 276, 271, 272, 273, 274, 275, 276, 277, 272, 273,
274, 275, 276, 277, 273, 274, 275, 276, 277, 278, 273, 274, 275,
276, 277, 278, 273, 274, 275, 276, 277, 278, 279, 274, 275, 276,
277, 278, 279, 274, 275, 276, 277, 278, 279, 280, 275, 276, 277,
278, 279, 280, 275, 276, 277, 278, 279, 280, 281, 276, 277, 278,
279, 280, 281, 276, 277, 278, 279, 280, 281, 282, 277, 278, 279,
280, 281, 282, 278, 279, 280, 281, 282, 283, 278, 279, 280, 281,
282, 283, 279, 280, 281, 282, 283, 284, 279, 280, 281, 282, 283,
284, 279, 280, 281, 282, 283, 284, 285, 280, 281, 282, 283, 284,
285, 280, 281, 282, 283, 284, 285, 286, 281, 282, 283, 284, 285,
286, 281, 282, 283, 284, 285, 286, 287, 282, 283, 284, 285, 286,
287, 283, 284, 285, 286, 287, 288, 283, 284, 285, 286, 287, 288,
284, 285, 286, 287, 288, 289, 284, 285, 286, 287, 288, 289, 290,
285, 286, 287, 288, 289, 290, 286, 287, 288, 289, 290, 291, 286,
287, 288, 289, 290, 291, 292, 287, 288, 289, 290, 291, 292, 287,
288, 289, 290, 291, 292, 293, 288, 289, 290, 291, 292, 293, 289,
290, 291, 292, 293, 294, 289, 290, 291, 292, 293, 294, 295, 290,
291, 292, 293, 294, 295, 296, 291, 292, 293, 294, 295, 296, 297,
292, 293, 294, 295, 296, 297, 292, 293, 294, 295, 296, 297, 298,
293, 294, 295, 296, 297, 298, 299, 294, 295, 296, 297, 298, 299,
300, 294, 295, 296, 297, 298, 299, 300, 301, 295, 296, 297, 298,
299, 300, 301, 302, 296, 297, 298, 299, 300, 301, 302, 297, 298,
299, 300, 301, 302, 303, 298, 299, 300, 301, 302, 303, 304, 299,
300, 301, 302, 303, 304, 305, 300, 301, 302, 303, 304, 305, 306,
301, 302, 303, 304, 305, 306, 307, 302, 303, 304, 305])
To reproduce the image, this MWE should be enough, once you copy-paste the arrays as px and py into your editor
import numpy as np
plot_mtx = np.zeros( (5120,5120) )
px=...
py=...
window_size = max(px[-1]-px[0],[py[-1]-py[0]])
imshow(plot_mtx[min(px):min(px)+window_size,min(py):min(py)+window_size])
Essentially, these are two lines that each have a width of about 6 pixels. I would like to separate them into two distinct lines, so that I would have px_1,py_1 for the one running from top to down, and px_2,py_2 for the one running from left to right.
I've failed so far to find the right keywords to find such algorithms. What I would have in mind is a for loop, that starts at one extremity, to complete a list with pixel positions in such a way, that the direction in which the loop is progressing never exceeds a certain angle with respect to several previous steps. This way, the algorithm would always take the set of pixels that cross smoothly through the intersection. Then it's just a matter of removing the new found line from the data and starting again.
Would you have any better input ?
Any feedback appreciated
Skeletonize the image.
Split by the crossing point(it has more than 2 neighbours) - that gives you 4 segments.
Join similarly directed pairs together - you get 2 skeleton lines.
Assign original pixels to each of those lines by proximity threshold.

Categories