LINUX.ORG.RU

Списки, хочу сравнить динамически созданные списки но у них нет индекса, как это сделать не создавая новый список?

 


1

1

Добрый день У меня есть 2 списка, которые я хочу сравнить, используя последний индекс каждого элемента[2], который представляет собой букву.

списки которые я хочу сравнить это maximum и maximum2

import copy

CATEGORIES = ["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","R","S","T","U","V","W","X","Y","Z"]
KR8877J = [[0.002,0.006,0.004,0.045,0.002,0.017,0.006,0.077,0.001,0.035,0.042,0.005,0.004,0.039,0.001,0.002,0.001,0.008,0.058,0.352,0.002,0.007,0.017,0.004,0.007,0.007,0.007,0.004,0.005,0.009,0.089,0.036,0.053,0.041,0.004],
[0.003,0.007,0.005,0.075,0.001,0.020,0.006,0.044,0.002,0.035,0.026,0.004,0.004,0.033,0.001,0.001,0.003,0.008,0.049,0.360,0.002,0.007,0.021,0.005,0.009,0.003,0.008,0.007,0.003,0.014,0.092,0.048,0.058,0.031,0.004],
[0.002,0.000,0.025,0.012,0.006,0.002,0.001,0.627,0.006,0.021,0.022,0.008,0.004,0.006,0.004,0.033,0.000,0.006,0.011,0.009,0.002,0.002,0.009,0.000,0.002,0.040,0.007,0.005,0.015,0.000,0.035,0.001,0.008,0.015,0.053],
[0.056,0.008,0.023,0.038,0.015,0.007,0.050,0.006,0.412,0.004,0.005,0.027,0.011,0.005,0.021,0.007,0.073,0.024,0.012,0.005,0.013,0.005,0.027,0.003,0.015,0.001,0.005,0.074,0.002,0.022,0.005,0.011,0.002,0.001,0.006],
[0.025,0.011,0.025,0.034,0.018,0.027,0.090,0.008,0.258,0.006,0.007,0.026,0.016,0.008,0.026,0.011,0.079,0.030,0.026,0.008,0.018,0.011,0.033,0.003,0.016,0.001,0.003,0.106,0.004,0.021,0.012,0.013,0.003,0.005,0.014],
[0.048,0.027,0.019,0.002,0.028,0.002,0.008,0.017,0.041,0.014,0.012,0.022,0.031,0.005,0.045,0.100,0.004,0.031,0.033,0.002,0.029,0.006,0.021,0.032,0.008,0.038,0.317,0.007,0.017,0.004,0.018,0.005,0.003,0.004,0.002],
[0.013,0.002,0.002,0.000,0.164,0.001,0.060,0.004,0.006,0.002,0.018,0.003,0.035,0.002,0.008,0.008,0.001,0.008,0.028,0.005,0.383,0.013,0.063,0.010,0.004,0.002,0.014,0.016,0.002,0.005,0.048,0.011,0.028,0.017,0.012]]
KR8877J_1 = [[0.004,0.007,0.005,0.042,0.002,0.014,0.011,0.054,0.002,0.032,0.051,0.005,0.005,0.044,0.001,0.002,0.002,0.008,0.056,0.389,0.003,0.008,0.023,0.005,0.009,0.005,0.009,0.006,0.004,0.010,0.070,0.029,0.049,0.031,0.005],
[0.005,0.005,0.005,0.034,0.002,0.006,0.005,0.083,0.002,0.062,0.053,0.004,0.006,0.039,0.001,0.002,0.001,0.008,0.055,0.348,0.002,0.005,0.020,0.005,0.011,0.011,0.018,0.004,0.005,0.008,0.086,0.018,0.055,0.020,0.004],
[0.001,0.001,0.024,0.009,0.013,0.003,0.002,0.499,0.006,0.011,0.022,0.011,0.007,0.006,0.006,0.048,0.000,0.008,0.013,0.009,0.004,0.002,0.007,0.000,0.002,0.053,0.009,0.007,0.030,0.000,0.030,0.001,0.009,0.021,0.123],
[0.039,0.008,0.029,0.041,0.013,0.008,0.054,0.005,0.369,0.004,0.005,0.023,0.011,0.005,0.020,0.005,0.100,0.022,0.012,0.005,0.012,0.007,0.028,0.002,0.015,0.000,0.003,0.102,0.001,0.021,0.006,0.012,0.002,0.002,0.007],
[0.031,0.007,0.018,0.032,0.015,0.017,0.075,0.008,0.365,0.005,0.005,0.028,0.015,0.005,0.022,0.011,0.075,0.027,0.014,0.005,0.020,0.006,0.025,0.002,0.014,0.001,0.004,0.099,0.003,0.016,0.008,0.009,0.002,0.002,0.010],
[0.046,0.022,0.022,0.002,0.031,0.003,0.008,0.022,0.047,0.011,0.010,0.039,0.035,0.005,0.048,0.110,0.002,0.028,0.031,0.003,0.029,0.006,0.016,0.022,0.007,0.059,0.289,0.005,0.016,0.003,0.013,0.004,0.002,0.004,0.003],
[0.019,0.004,0.002,0.000,0.134,0.004,0.088,0.006,0.004,0.003,0.016,0.007,0.037,0.004,0.016,0.014,0.002,0.014,0.026,0.005,0.342,0.019,0.049,0.024,0.004,0.003,0.021,0.009,0.005,0.009,0.049,0.012,0.017,0.026,0.006]]
KR8877J_2 = [[0.002,0.005,0.005,0.046,0.002,0.014,0.008,0.073,0.002,0.023,0.042,0.004,0.007,0.027,0.001,0.003,0.001,0.006,0.047,0.384,0.005,0.006,0.015,0.003,0.006,0.004,0.011,0.006,0.006,0.005,0.088,0.027,0.066,0.040,0.010],
[0.002,0.005,0.005,0.039,0.002,0.009,0.005,0.089,0.001,0.036,0.043,0.004,0.006,0.026,0.001,0.002,0.001,0.006,0.051,0.387,0.003,0.005,0.014,0.003,0.007,0.007,0.014,0.004,0.007,0.005,0.090,0.022,0.064,0.030,0.006],
[0.002,0.001,0.014,0.011,0.020,0.005,0.004,0.282,0.005,0.012,0.022,0.011,0.009,0.010,0.008,0.041,0.000,0.017,0.030,0.019,0.009,0.003,0.009,0.000,0.004,0.053,0.010,0.016,0.049,0.000,0.043,0.002,0.017,0.037,0.224],
[0.028,0.015,0.029,0.039,0.023,0.020,0.097,0.008,0.239,0.004,0.009,0.021,0.019,0.008,0.017,0.008,0.082,0.023,0.025,0.012,0.020,0.010,0.037,0.003,0.016,0.001,0.003,0.110,0.003,0.019,0.012,0.014,0.004,0.005,0.015],
[0.037,0.013,0.035,0.053,0.025,0.022,0.057,0.017,0.250,0.005,0.009,0.037,0.025,0.008,0.029,0.013,0.057,0.029,0.029,0.009,0.015,0.009,0.027,0.002,0.020,0.002,0.006,0.092,0.006,0.012,0.011,0.011,0.003,0.004,0.021],
[0.036,0.022,0.024,0.003,0.022,0.004,0.011,0.019,0.069,0.014,0.011,0.035,0.045,0.006,0.057,0.096,0.004,0.037,0.030,0.004,0.039,0.007,0.021,0.018,0.010,0.031,0.256,0.013,0.018,0.003,0.018,0.005,0.004,0.006,0.004],
[0.015,0.003,0.002,0.000,0.174,0.004,0.085,0.008,0.005,0.002,0.015,0.008,0.028,0.003,0.013,0.016,0.001,0.015,0.029,0.004,0.357,0.013,0.043,0.017,0.003,0.003,0.017,0.010,0.004,0.007,0.037,0.013,0.015,0.020,0.010]]
KR8877J_3 = [[0.005,0.006,0.006,0.055,0.002,0.017,0.009,0.076,0.003,0.035,0.032,0.007,0.005,0.050,0.001,0.002,0.002,0.011,0.050,0.391,0.002,0.005,0.018,0.003,0.012,0.009,0.009,0.005,0.005,0.012,0.068,0.032,0.032,0.017,0.006],
[0.009,0.005,0.007,0.064,0.002,0.022,0.009,0.040,0.003,0.030,0.026,0.010,0.006,0.069,0.001,0.001,0.004,0.011,0.040,0.379,0.002,0.009,0.021,0.005,0.017,0.007,0.009,0.005,0.003,0.034,0.063,0.035,0.029,0.017,0.006],
[0.001,0.001,0.014,0.011,0.011,0.004,0.003,0.458,0.004,0.012,0.023,0.010,0.007,0.009,0.006,0.039,0.000,0.012,0.016,0.014,0.005,0.003,0.007,0.000,0.002,0.052,0.008,0.009,0.039,0.000,0.036,0.001,0.013,0.032,0.139],
[0.042,0.012,0.023,0.029,0.043,0.015,0.111,0.010,0.235,0.004,0.009,0.036,0.023,0.010,0.018,0.010,0.039,0.029,0.024,0.012,0.025,0.009,0.041,0.003,0.019,0.002,0.005,0.084,0.004,0.018,0.013,0.012,0.004,0.005,0.023],
[0.030,0.008,0.017,0.033,0.011,0.020,0.103,0.009,0.289,0.004,0.006,0.030,0.022,0.007,0.021,0.011,0.108,0.031,0.013,0.008,0.020,0.006,0.023,0.002,0.018,0.001,0.004,0.102,0.005,0.012,0.007,0.007,0.002,0.003,0.009],
[0.034,0.024,0.018,0.003,0.025,0.005,0.008,0.025,0.053,0.010,0.008,0.045,0.036,0.006,0.050,0.119,0.002,0.035,0.028,0.003,0.029,0.005,0.014,0.017,0.007,0.060,0.275,0.006,0.019,0.002,0.013,0.004,0.003,0.006,0.005],
[0.016,0.004,0.002,0.000,0.130,0.003,0.080,0.005,0.004,0.003,0.017,0.005,0.038,0.002,0.015,0.014,0.002,0.011,0.027,0.004,0.378,0.016,0.051,0.019,0.004,0.002,0.020,0.012,0.004,0.006,0.040,0.013,0.023,0.020,0.008]]
KR8877J_4 = [[0.006,0.004,0.007,0.052,0.002,0.012,0.005,0.066,0.002,0.043,0.036,0.007,0.007,0.051,0.001,0.001,0.002,0.008,0.037,0.401,0.002,0.008,0.017,0.004,0.013,0.010,0.014,0.004,0.004,0.016,0.077,0.021,0.038,0.018,0.006],
[0.001,0.001,0.012,0.008,0.013,0.004,0.002,0.462,0.004,0.011,0.022,0.008,0.006,0.006,0.006,0.052,0.000,0.012,0.018,0.012,0.005,0.002,0.007,0.000,0.002,0.046,0.009,0.009,0.040,0.000,0.039,0.002,0.012,0.031,0.136],
[0.004,0.003,0.007,0.042,0.001,0.008,0.005,0.060,0.002,0.062,0.050,0.005,0.004,0.053,0.000,0.001,0.002,0.006,0.033,0.422,0.001,0.008,0.017,0.004,0.011,0.007,0.010,0.003,0.002,0.013,0.065,0.024,0.045,0.017,0.003],
[0.029,0.015,0.032,0.058,0.018,0.013,0.067,0.012,0.287,0.006,0.010,0.025,0.016,0.007,0.017,0.009,0.059,0.023,0.026,0.011,0.016,0.006,0.033,0.003,0.017,0.001,0.006,0.118,0.004,0.014,0.009,0.012,0.004,0.003,0.012],
[0.056,0.011,0.024,0.034,0.027,0.015,0.065,0.013,0.271,0.006,0.007,0.062,0.028,0.013,0.026,0.014,0.030,0.039,0.027,0.011,0.019,0.006,0.031,0.003,0.027,0.005,0.009,0.061,0.006,0.014,0.011,0.006,0.002,0.004,0.016],
[0.041,0.020,0.022,0.002,0.019,0.004,0.007,0.024,0.046,0.016,0.008,0.051,0.036,0.006,0.051,0.109,0.002,0.030,0.027,0.003,0.024,0.005,0.015,0.017,0.008,0.067,0.286,0.005,0.015,0.003,0.014,0.003,0.002,0.005,0.003],
[0.014,0.003,0.002,0.000,0.106,0.007,0.079,0.007,0.004,0.003,0.014,0.010,0.041,0.004,0.013,0.011,0.001,0.014,0.031,0.007,0.377,0.022,0.049,0.017,0.004,0.003,0.014,0.009,0.004,0.009,0.050,0.013,0.016,0.034,0.008]]
KR8877J_5 = [[0.008,0.004,0.008,0.064,0.001,0.018,0.009,0.041,0.003,0.043,0.035,0.008,0.005,0.076,0.001,0.001,0.004,0.009,0.037,0.382,0.001,0.011,0.024,0.005,0.015,0.006,0.007,0.005,0.002,0.030,0.057,0.031,0.029,0.017,0.004],
[0.002,0.004,0.004,0.044,0.001,0.012,0.005,0.068,0.001,0.043,0.052,0.003,0.005,0.030,0.001,0.002,0.001,0.007,0.041,0.350,0.003,0.007,0.019,0.005,0.007,0.004,0.011,0.005,0.003,0.007,0.099,0.035,0.076,0.038,0.004],
[0.001,0.001,0.015,0.011,0.009,0.004,0.002,0.517,0.004,0.012,0.028,0.007,0.005,0.007,0.005,0.035,0.000,0.011,0.014,0.012,0.005,0.003,0.010,0.000,0.002,0.030,0.006,0.009,0.029,0.000,0.039,0.002,0.016,0.034,0.114],
[0.026,0.010,0.036,0.064,0.011,0.009,0.052,0.010,0.360,0.004,0.007,0.022,0.015,0.005,0.017,0.006,0.067,0.019,0.017,0.008,0.013,0.006,0.026,0.002,0.015,0.001,0.004,0.121,0.003,0.011,0.006,0.010,0.003,0.002,0.011],
[0.044,0.017,0.027,0.037,0.024,0.016,0.079,0.010,0.259,0.006,0.009,0.032,0.023,0.009,0.022,0.012,0.064,0.031,0.026,0.010,0.019,0.007,0.034,0.004,0.021,0.002,0.007,0.086,0.005,0.018,0.011,0.011,0.003,0.003,0.011],
[0.033,0.013,0.021,0.002,0.014,0.003,0.006,0.023,0.033,0.015,0.009,0.048,0.040,0.007,0.056,0.098,0.002,0.032,0.023,0.003,0.023,0.006,0.013,0.015,0.009,0.069,0.331,0.005,0.018,0.002,0.012,0.003,0.002,0.005,0.003],
[0.017,0.004,0.002,0.000,0.096,0.008,0.095,0.007,0.004,0.003,0.013,0.012,0.045,0.006,0.017,0.013,0.002,0.016,0.029,0.007,0.360,0.023,0.045,0.023,0.005,0.004,0.018,0.008,0.005,0.010,0.042,0.011,0.013,0.032,0.007]]
KR8877J_6 = [[0.007,0.004,0.007,0.082,0.002,0.023,0.009,0.029,0.003,0.024,0.024,0.008,0.006,0.062,0.001,0.001,0.005,0.009,0.032,0.391,0.002,0.012,0.020,0.005,0.016,0.004,0.006,0.006,0.002,0.037,0.061,0.041,0.033,0.019,0.006],
[0.004,0.004,0.008,0.078,0.001,0.013,0.005,0.059,0.002,0.044,0.041,0.006,0.005,0.052,0.001,0.001,0.002,0.008,0.036,0.366,0.001,0.010,0.015,0.003,0.011,0.008,0.008,0.005,0.004,0.015,0.074,0.035,0.045,0.023,0.007],
[0.001,0.001,0.013,0.010,0.015,0.006,0.004,0.299,0.004,0.011,0.021,0.011,0.009,0.010,0.009,0.044,0.000,0.021,0.023,0.017,0.008,0.004,0.007,0.000,0.003,0.056,0.008,0.014,0.056,0.000,0.040,0.002,0.016,0.039,0.217],
[0.021,0.011,0.022,0.060,0.018,0.026,0.090,0.014,0.234,0.005,0.011,0.025,0.016,0.009,0.015,0.011,0.052,0.030,0.029,0.015,0.019,0.007,0.030,0.003,0.016,0.001,0.003,0.134,0.006,0.013,0.011,0.014,0.004,0.005,0.020],
[0.031,0.012,0.027,0.036,0.023,0.020,0.053,0.018,0.269,0.006,0.008,0.029,0.036,0.007,0.029,0.021,0.046,0.030,0.028,0.009,0.023,0.007,0.027,0.003,0.020,0.002,0.010,0.098,0.010,0.009,0.016,0.009,0.004,0.005,0.018],
[0.036,0.019,0.017,0.002,0.027,0.004,0.009,0.027,0.063,0.012,0.008,0.045,0.035,0.006,0.050,0.140,0.002,0.036,0.030,0.003,0.031,0.004,0.017,0.016,0.007,0.055,0.239,0.007,0.018,0.002,0.014,0.004,0.003,0.006,0.004],
[0.018,0.004,0.002,0.000,0.186,0.004,0.107,0.005,0.005,0.003,0.010,0.008,0.041,0.004,0.017,0.018,0.001,0.012,0.034,0.004,0.300,0.014,0.036,0.018,0.004,0.004,0.020,0.010,0.005,0.008,0.049,0.009,0.011,0.020,0.008]]
 

 
seq = (KR8877J, KR8877J_1, KR8877J_2, KR8877J_3, KR8877J_4, KR8877J_5, KR8877J_6)
if __name__ == "__main__":
 
    max_index = 0
    max_list_from_all_plates = []
    Secondplate =None
    threshold = 0.05
    listy  = []

    for single_lp in seq:
        maximum_plate_prob = []
        possible_plate_prob = []
        max_list = []
    
        for sign in single_lp:
            high_indexes = []
            for prob_id in range(0,len(sign)):
                if threshold<sign[prob_id]:
                    high_indexes.append([sign[prob_id], prob_id, CATEGORIES[prob_id]])
            max_list.append(high_indexes)
            
        max_list_from_all_plates.append(max_list)
        h = high_indexes[0]
        newlist = copy.deepcopy(max_list)

        maximum = [max(h) for h in max_list]
        listy.append(maximum)

        m = [max(h) for h in newlist]
            

        n = 0 
        for i in newlist:
            i.remove(m[n])
            n += 1

        maximum2 = [max(h) for h in newlist]
        
        print(maximum, maximum2)
    print(max_list_from_all_plates)

My output: [[0.352, 19, 'J'], [0.36, 19, 'J'], [0.627, 7, '7'], [0.412, 8, '8'], [0.258, 8, '8'], [0.317, 26, 'R'], [0.383, 20, 'K']] [[0.089, 30, 'V'], [0.092, 30, 'V'], [0.053, 34, 'Z'], [0.074, 27, 'S'], [0.106, 27, 'S'], [0.1, 15, 'F'], [0.164, 4, '4']]

I want to compare letters more or less like K || K, R || R or KR8877J || KR8877J to see if they are the same.


Последнее исправление: katemisik (всего исправлений: 4)

опять филиал русского стэковервлоу разводят, неужели на лоре находится кто-то кто с такими домашками помогает?..

ei-grad ★★★★★
()

Хочу скомбинировать с этих максимумов списки вероятных символов не теряя их порядок

Сложите свои данные в словарь (points = { 'KR8877J': [[ ... ]], 'KR8877J_1' : [[ ... ]], ... }), а ключи этого словаря - в массивы. Сразу появится возможность обрабатывать их пакетно, с сохранением имён и порядка.

anonymous
()
Ответ на: комментарий от ei-grad

неужели на лоре находится кто-то кто помогает?

Нет, среди регистроты таких не осталось.

anonymous
()
Ответ на: комментарий от anonymous

я стараюсь не использовать громостких решений, моя програма должна работать динамически точнее динамически обрабатывать данные, извдекая самые максимальные значения и все. Чтобы итог не огромное количество данных и еще большее хранилище для них а тх обработка и вывод самых вероятных значений

katemisik
() автор топика

Сравнить списки:

‘list1 == list2’

Почему каждый раз вместо вопроса по существу портянка какого-то говна?

anonymous
()
Ответ на: комментарий от katemisik

Желаю, чтобы причиной твоей смерти стал упавший на голову учебник по русскому языку…

@Zhbert, как можно такое терпеть?

anonymous
()

Вы, очевидно, пытаетесь решить какую-то задачу. Только из вашего описания совершенно непонятно, ни что у вас есть, ни что надо сделать.

Судя по вашему коду у вас есть список списков newlist и есть список списков списков max_list_from_all_plates («максимальный список со всех тарелок»? 😮)

Что лежит в этих всех списках? И что вы пытаетесь в них найти?

Уточните:
1. Что является входными данными программы, и в каком виде они заданы?
2. Что программа должна вывести на экран?

anonymous
()
Ответ на: комментарий от anonymous

я хочу сравнить списки которые есть у меня в output

[[0.089, 30, 'V'], [0.092, 30, 'V'], [0.053, 34, 'Z'], [0.074, 27, 'S'], [0.106, 27, 'S'], [0.1, 15, 'F'], [0.164, 4, '4']]
[[0.07, 30, 'V'], [0.086, 30, 'V'], [0.123, 34, 'Z'], [0.102, 27, 'S'], [0.099, 27, 'S'], [0.11, 15, 'F'], [0.134, 4, '4']]
[[0.088, 30, 'V'], [0.09, 30, 'V'], [0.224, 34, 'Z'], [0.11, 27, 'S'], [0.092, 27, 'S'], [0.096, 15, 'F'], [0.174, 4, '4']]
[[0.076, 7, '7'], [0.069, 13, 'D'], [0.139, 34, 'Z'], [0.111, 6, '6'], [0.108, 16, 'G'], [0.119, 15, 'F'], [0.13, 4, '4']] 
[[0.077, 30, 'V'], [0.136, 34, 'Z'], [0.065, 30, 'V'], [0.118, 27, 'S'], [0.065, 6, '6'], [0.109, 15, 'F'], [0.106, 4, '4']]
[[0.076, 13, 'D'], [0.099, 30, 'V'], [0.114, 34, 'Z'], [0.121, 27, 'S'], [0.086, 27, 'S'], [0.098, 15, 'F'], [0.096, 4, '4']]
[[0.082, 3, '3'], [0.078, 3, '3'], [0.217, 34, 'Z'], [0.134, 27, 'S'], [0.098, 27, 'S'], [0.14, 15, 'F'], [0.186, 4, '4']]
[[0.352, 19, 'J'], [0.36, 19, 'J'], [0.627, 7, '7'], [0.412, 8, '8'], [0.258, 8, '8'], [0.317, 26, 'R'], [0.383, 20, 'K']]
[[0.389, 19, 'J'], [0.348, 19, 'J'], [0.499, 7, '7'], [0.369, 8, '8'], [0.365, 8, '8'], [0.289, 26, 'R'], [0.342, 20, 'K']]
[[0.384, 19, 'J'], [0.387, 19, 'J'], [0.282, 7, '7'], [0.239, 8, '8'], [0.25, 8, '8'], [0.256, 26, 'R'], [0.357, 20, 'K']]
[[0.391, 19, 'J'], [0.379, 19, 'J'], [0.458, 7, '7'], [0.235, 8, '8'], [0.289, 8, '8'], [0.275, 26, 'R'], [0.378, 20, 'K']]
[[0.401, 19, 'J'], [0.462, 7, '7'], [0.422, 19, 'J'], [0.287, 8, '8'], [0.271, 8, '8'], [0.286, 26, 'R'], [0.377, 20, 'K']]
[[0.382, 19, 'J'], [0.35, 19, 'J'], [0.517, 7, '7'], [0.36, 8, '8'], [0.259, 8, '8'], [0.331, 26, 'R'], [0.36, 20, 'K']]
[[0.391, 19, 'J'], [0.366, 19, 'J'], [0.299, 7, '7'], [0.234, 8, '8'], [0.269, 8, '8'], [0.239, 26, 'R'], [0.3, 20, 'K']]

и я почему то не могу сделать их одним списком или вызвать их по индексу.. вот как я их создаю

        newlist = copy.deepcopy(max_list)

        maximum = [max(h) for h in max_list]
        listy.append(maximum)

        m = [max(h) for h in newlist]
        

        n = 0 
        for i in newlist:
            i.remove(m[n])
            n += 1



        maximum2 = [max(h) for h in newlist]
        print(maximum2)
    #print(listy)
    n = 0
    n += n


    for x in listy:
        print(x)

вот пример данных``` KR8877J = [[0.002,0.006,0.004,0.045,0.002,0.017,0.006,0.077,0.001,0.035,0.042,0.005,0.004,0.039,0.001,0.002,0.001,0.008,0.058,0.352,0.002,0.007,0.017,0.004,0.007,0.007,0.007,0.004,0.005,0.009,0.089,0.036,0.053,0.041,0.004], [0.003,0.007,0.005,0.075,0.001,0.020,0.006,0.044,0.002,0.035,0.026,0.004,0.004,0.033,0.001,0.001,0.003,0.008,0.049,0.360,0.002,0.007,0.021,0.005,0.009,0.003,0.008,0.007,0.003,0.014,0.092,0.048,0.058,0.031,0.004], [0.002,0.000,0.025,0.012,0.006,0.002,0.001,0.627,0.006,0.021,0.022,0.008,0.004,0.006,0.004,0.033,0.000,0.006,0.011,0.009,0.002,0.002,0.009,0.000,0.002,0.040,0.007,0.005,0.015,0.000,0.035,0.001,0.008,0.015,0.053], [0.056,0.008,0.023,0.038,0.015,0.007,0.050,0.006,0.412,0.004,0.005,0.027,0.011,0.005,0.021,0.007,0.073,0.024,0.012,0.005,0.013,0.005,0.027,0.003,0.015,0.001,0.005,0.074,0.002,0.022,0.005,0.011,0.002,0.001,0.006], [0.025,0.011,0.025,0.034,0.018,0.027,0.090,0.008,0.258,0.006,0.007,0.026,0.016,0.008,0.026,0.011,0.079,0.030,0.026,0.008,0.018,0.011,0.033,0.003,0.016,0.001,0.003,0.106,0.004,0.021,0.012,0.013,0.003,0.005,0.014], [0.048,0.027,0.019,0.002,0.028,0.002,0.008,0.017,0.041,0.014,0.012,0.022,0.031,0.005,0.045,0.100,0.004,0.031,0.033,0.002,0.029,0.006,0.021,0.032,0.008,0.038,0.317,0.007,0.017,0.004,0.018,0.005,0.003,0.004,0.002], [0.013,0.002,0.002,0.000,0.164,0.001,0.060,0.004,0.006,0.002,0.018,0.003,0.035,0.002,0.008,0.008,0.001,0.008,0.028,0.005,0.383,0.013,0.063,0.010,0.004,0.002,0.014,0.016,0.002,0.005,0.048,0.011,0.028,0.017,0.012]]

как вы видите я ищу максимальные значения с каждой буквы maximum
потом ищу второе максимальное значение maximum2
katemisik
() автор топика
Ответ на: комментарий от katemisik

Я всё ещё не совсем понимаю, что вы пытаетесь сделать...

Очевидно, у нас есть 35 символов (все цифры и буквы, кроме «Q»):

CATEGORIES = ["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","R","S","T","U","V","W","X","Y","Z"]

И есть какой-то список частот встречаемости этих символов:

KR8877J = [ [тут 35 чисел],
            [другие 35 чисел],
            [и ещё 35 чисел],
            [и тут 35 чисел],
            [тоже 35 чисел],
            [и ещё 35 чисел],
            [и последние 35 чисел] ]

Только почему-то у нас не 1 список частот, а 7 списков, лежащих в переменной KR8877J.

И таких KR8877J-ов у нас тоже 7 штук.

Получается матрица 7x7, в каждой ячейке которой лежит список частот символов.

Тогда ваш код, который ищет максимумы, сводится к:

CATEGORIES = [ ... ]
KR8877J = [ ... ]
KR8877J_1 = [ ... ]
KR8877J_2 = [ ... ]
KR8877J_3 = [ ... ]
KR8877J_4 = [ ... ]
KR8877J_5 = [ ... ]
KR8877J_6 = [ ... ]

for row in (KR8877J, KR8877J_1, KR8877J_2, KR8877J_3, KR8877J_4, KR8877J_5, KR8877J_6):
    maximum, maximum2 = [], []
    for freqs in row:
        # оставляем только символы, которые встречаются чаще чем 5%, не знаю зачем
        # а чтобы было видно, какие это символы, приклеиваем сам символ к каждому числу
        high_indexes = [ [freq,char] for freq,char in zip(freqs, CATEGORIES) if freq>0.05 ]
        # записываем "самый частовстречающийся" и "второй частовстречающийся" в maximum и maximum2:
        max2, max1 = sorted(high_indexes)[-2:]
        maximum.append(max1)
        maximum2.append(max2)
    print("max1 = %s" % maximum)
    print("max2 = %s" % maximum2)

И этот код пишет:

max1 = [[0.352,'J'], [0.360,'J'], [0.627,'7'], [0.412,'8'], [0.258,'8'], [0.317,'R'], [0.383,'K']]
max2 = [[0.089,'V'], [0.092,'V'], [0.053,'Z'], [0.074,'S'], [0.106,'S'], [0.100,'F'], [0.164,'4']]
max1 = [[0.389,'J'], [0.348,'J'], [0.499,'7'], [0.369,'8'], [0.365,'8'], [0.289,'R'], [0.342,'K']]
max2 = [[0.070,'V'], [0.086,'V'], [0.123,'Z'], [0.102,'S'], [0.099,'S'], [0.110,'F'], [0.134,'4']]
max1 = [[0.384,'J'], [0.387,'J'], [0.282,'7'], [0.239,'8'], [0.250,'8'], [0.256,'R'], [0.357,'K']]
max2 = [[0.088,'V'], [0.090,'V'], [0.224,'Z'], [0.110,'S'], [0.092,'S'], [0.096,'F'], [0.174,'4']]
max1 = [[0.391,'J'], [0.379,'J'], [0.458,'7'], [0.235,'8'], [0.289,'8'], [0.275,'R'], [0.378,'K']]
max2 = [[0.076,'7'], [0.069,'D'], [0.139,'Z'], [0.111,'6'], [0.108,'G'], [0.119,'F'], [0.130,'4']]
max1 = [[0.401,'J'], [0.462,'7'], [0.422,'J'], [0.287,'8'], [0.271,'8'], [0.286,'R'], [0.377,'K']]
max2 = [[0.077,'V'], [0.136,'Z'], [0.065,'V'], [0.118,'S'], [0.065,'6'], [0.109,'F'], [0.106,'4']]
max1 = [[0.382,'J'], [0.350,'J'], [0.517,'7'], [0.360,'8'], [0.259,'8'], [0.331,'R'], [0.360,'K']]
max2 = [[0.076,'D'], [0.099,'V'], [0.114,'Z'], [0.121,'S'], [0.086,'S'], [0.098,'F'], [0.096,'4']]
max1 = [[0.391,'J'], [0.366,'J'], [0.299,'7'], [0.234,'8'], [0.269,'8'], [0.239,'R'], [0.300,'K']]
max2 = [[0.082,'3'], [0.078,'3'], [0.217,'Z'], [0.134,'S'], [0.098,'S'], [0.140,'F'], [0.186,'4']]

Ну, вот они — максимумы, два самых часто встречающиеся символа в каждом списке частот из каждого KR8877J-а.

я хочу сравнить списки которые есть у меня в output

В каком смысле, «сравнить»? С чем? Между собой? Ну, очевидно частоты тут не равны... Это невооружённым глазом видно. 🙂

PS: Скажите хоть, что все эти частоты значат.

anonymous
()
Ответ на: комментарий от anonymous

Кстати, если эти строки max1=... и max1=... сгруппировать вместе, то получатся как бы две матрицы:

max1 = [[0.352,'J'], [0.360,'J'], [0.627,'7'], [0.412,'8'], [0.258,'8'], [0.317,'R'], [0.383,'K']]
max1 = [[0.389,'J'], [0.348,'J'], [0.499,'7'], [0.369,'8'], [0.365,'8'], [0.289,'R'], [0.342,'K']]
max1 = [[0.384,'J'], [0.387,'J'], [0.282,'7'], [0.239,'8'], [0.250,'8'], [0.256,'R'], [0.357,'K']]
max1 = [[0.391,'J'], [0.379,'J'], [0.458,'7'], [0.235,'8'], [0.289,'8'], [0.275,'R'], [0.378,'K']]
max1 = [[0.401,'J'], [0.462,'7'], [0.422,'J'], [0.287,'8'], [0.271,'8'], [0.286,'R'], [0.377,'K']]
max1 = [[0.382,'J'], [0.350,'J'], [0.517,'7'], [0.360,'8'], [0.259,'8'], [0.331,'R'], [0.360,'K']]
max1 = [[0.391,'J'], [0.366,'J'], [0.299,'7'], [0.234,'8'], [0.269,'8'], [0.239,'R'], [0.300,'K']]

max2 = [[0.089,'V'], [0.092,'V'], [0.053,'Z'], [0.074,'S'], [0.106,'S'], [0.100,'F'], [0.164,'4']]
max2 = [[0.070,'V'], [0.086,'V'], [0.123,'Z'], [0.102,'S'], [0.099,'S'], [0.110,'F'], [0.134,'4']]
max2 = [[0.088,'V'], [0.090,'V'], [0.224,'Z'], [0.110,'S'], [0.092,'S'], [0.096,'F'], [0.174,'4']]
max2 = [[0.076,'7'], [0.069,'D'], [0.139,'Z'], [0.111,'6'], [0.108,'G'], [0.119,'F'], [0.130,'4']]
max2 = [[0.077,'V'], [0.136,'Z'], [0.065,'V'], [0.118,'S'], [0.065,'6'], [0.109,'F'], [0.106,'4']]
max2 = [[0.076,'D'], [0.099,'V'], [0.114,'Z'], [0.121,'S'], [0.086,'S'], [0.098,'F'], [0.096,'4']]
max2 = [[0.082,'3'], [0.078,'3'], [0.217,'Z'], [0.134,'S'], [0.098,'S'], [0.140,'F'], [0.186,'4']]

Очевидно, они не равны. Тут почти все элементы отличаются. Но с этим дальше делать-то?

anonymous
()
Ответ на: комментарий от anonymous

Постараюсь донести свою идею. Я хочу сравнить по категориям то есть по буквам и потом после составления списка J, J, 7, 8, 8, R ,K - вероятность которого равна от 2,7(если сложить первые колонки или ж индекс [0] каждого елемента - 0.352+0.360+0.627+0.412+0.258,+0.317,+0.383 ) и до нп. 2.1 … то есть аутпут плюс минус J, J, 7, 8, 8, R ,K qual 2,7 to 2.1 J, 7, J, 8, 8, R ,K equal 1.9 to 1.7

так же я хочу увеличить диапазон с двух значений J, J, 7, 8, 8, R ,K до J, 7, j, 8, 8, R ,K подбирая к ним наиболее высокие максимумы со второго списка .

к примеру

со всех вторых максимумов самые максимальный символ это Z c списка max2 = [[0.088,‘V’], [0.090,‘V’], [0.224,‘Z’], [0.110,‘S’], [0.092,‘S’], [0.096,‘F’], [0.174,‘4’]] желательный итог J, J, Z, 8, 8, R ,K - Третий лучший вариант спасибо за Ваше время и помощь!

katemisik
() автор топика
Ответ на: комментарий от katemisik

так же я не использую готовую сортировку max2, max1 = sorted(high_indexes)[-2:]

Это не проблема. Можно заменить строку:

max2, max1 = sorted(high_indexes)[-2:]
например, на строку:
max1 = max(high_indexes)
max2 = max(h for h in high_indexes if h != max1)

anonymous
()
Ответ на: комментарий от katemisik

подбирая к ним наиболее высокие максимумы со второго списка .
к примеру
со всех вторых максимумов самые максимальный символ это Z c списка
max2 = [[0.088,‘V’], [0.090,‘V’], [0.224,‘Z’], [0.110,‘S’], [0.092,‘S’], [0.096,‘F’], [0.174,‘4’]]
желательный итог J, J, Z, 8, 8, R ,K - Третий лучший вариант

То есть надо найти наибольший элемент в списке maximum2, и подставить его на то же место в списке maximum?

Это ещё пара строк:

    ...
    print("max1 = %s" % maximum)
    print("max2 = %s" % maximum2)
    max_in_max2 = max(maximum2)
    maximum3 = [ m2 if m2==max_in_max2 else m1  for m1,m2 in zip(maximum,maximum2) ]
    print("max3 = %s" % maximum3)

И напишет он:

max3 = [[0.352,'J'], [0.360,'J'], [0.627,'7'], [0.412,'8'], [0.258,'8'], [0.317,'R'], [0.164,'4']]
max3 = [[0.389,'J'], [0.348,'J'], [0.499,'7'], [0.369,'8'], [0.365,'8'], [0.289,'R'], [0.134,'4']]
max3 = [[0.384,'J'], [0.387,'J'], [0.224,'Z'], [0.239,'8'], [0.250,'8'], [0.256,'R'], [0.357,'K']]
max3 = [[0.391,'J'], [0.379,'J'], [0.139,'Z'], [0.235,'8'], [0.289,'8'], [0.275,'R'], [0.378,'K']]
max3 = [[0.401,'J'], [0.136,'Z'], [0.422,'J'], [0.287,'8'], [0.271,'8'], [0.286,'R'], [0.377,'K']]
max3 = [[0.382,'J'], [0.350,'J'], [0.517,'7'], [0.121,'S'], [0.259,'8'], [0.331,'R'], [0.360,'K']]
max3 = [[0.391,'J'], [0.366,'J'], [0.217,'Z'], [0.234,'8'], [0.269,'8'], [0.239,'R'], [0.300,'K']]
Получили J, J, Z, 8, 8, R, K.

Но я всё еще не понимаю, что вы пытаетесь узнать, и зачем вам это надо. Математически не понимаю.

вероятность которого равна от 2,7

Это не имеет смысла. Вероятность не может быть больше 1. Вероятности независимых событий не суммируются.

anonymous
()
Ответ на: комментарий от ei-grad

Нет, на Лоре только пердят в тредах, так же как и ты.

anonymous
()
Ответ на: комментарий от anonymous

это данные с картинок с текстом, итог много картинок одного обекта и нужны все вероятности, или же от максимальной вероятности к мнее возможным, спасибо за вашу помощь!

katemisik
() автор топика
Ответ на: комментарий от anonymous

я хотела бы использовать списки и функцию max(). вместо создания словарей zip и им подобных, но пока не нашла такого способа

katemisik
() автор топика
Ответ на: комментарий от anonymous

не знаю так ли у вас работает ваща функия max_in_max2 = max(maximum2) print(max_in_max2) max_in_max1 = max(maximum) print(max_in_max1) но у меня она показывает не список с максимальным значением что помоему значитт что она работает не верно или же вы ее для чего то другого используете,? у меня она показывает список [[0.401, 19, ‘J’], [0.462, 7, ‘7’], [0.422, 19, ‘J’], [0.287, 8, ‘8’], [0.271, 8, ‘8’], [0.286, 26, ‘R’], [0.377, 20, ‘K’]] - по сумме первых елементов равно 2,5 вместо списка [[[0.352, 19, ‘J’], [0.36, 19, ‘J’], [0.627, 7, ‘7’], [0.412, 8, ‘8’], [0.258, 8, ‘8’], [0.317, 26, ‘R’], [0.383, 20, ‘K’]], который равен 2.709 и являеться максимальным..

katemisik
() автор топика
Ответ на: комментарий от katemisik

это данные с картинок с текстом, итог много картинок одного обекта и нужны все вероятности, или же от максимальной вероятности к мнее возможным

Распознавание символов?

Тогда просто берите максимальную вероятность для каждой картинки. Зачем вам второй и третий максимумы?

я хотела бы использовать списки и функцию max(). вместо создания словарей zip и им подобных, но пока не нашла такого способа

Zip не создаёт словарь. Zip просто склеивает элементы попарно, чтобы их было удобнее перебирать.

То есть код:

    max_in_max2 = max(maximum2)
    maximum3 = [ m2 if m2==max_in_max2 else m1  for m1,m2 in zip(maximum,maximum2) ]
Делает примерно то же самое, что и код:
    max_in_max2 = max(maximum2)
    maximum3 = [ maximum2[i] if maximum2[i]==max_in_max2 else maximum[i]  for i in range(len(maximum)) ]
но второй вариант длиннее.

не знаю так ли у вас работает ваща функия max_in_max2 = max(maximum2) print(max_in_max2) max_in_max1 = max(maximum) print(max_in_max1) но у меня она показывает не список с максимальным значением что помоему значитт что она работает не верно или же вы ее для чего то другого используете,? у меня она показывает список [[0.401, 19, ‘J’], [0.462, 7, ‘7’], [0.422, 19, ‘J’], [0.287, 8, ‘8’], [0.271, 8, ‘8’], [0.286, 26, ‘R’], [0.377, 20, ‘K’]] - по сумме первых елементов равно 2,5 вместо списка [[[0.352, 19, ‘J’], [0.36, 19, ‘J’], [0.627, 7, ‘7’], [0.412, 8, ‘8’], [0.258, 8, ‘8’], [0.317, 26, ‘R’], [0.383, 20, ‘K’]], который равен 2.709 и являеться максимальным..

Всё верно. Вы их просто перепутали.

Это:

[[0.401, 19, ‘J’], [0.462, 7, ‘7’], [0.422, 19, ‘J’], [0.287, 8, ‘8’], [0.271, 8, ‘8’], [0.286, 26, ‘R’], [0.377, 20, ‘K’]]
^ это список maximum[] для переменной KR8877J_4.

А это:

[[0.352, 19, ‘J’], [0.36, 19, ‘J’], [0.627, 7, ‘7’], [0.412, 8, ‘8’], [0.258, 8, ‘8’], [0.317, 26, ‘R’], [0.383, 20, ‘K’]]
^ это список maximum[] для другой переменной — KR8877J.

anonymous
()
Ответ на: комментарий от anonymous

есть ли такая возможность обойтись без zip dir ? может с помощью индексов? например

for max1 in maximum:
    letters = ([item[2] for item in max1])

    row = []

    row.append(letters)
    letterslist.append(row)


    print(max1)

заранее спасибо!

anonymous
()
Ответ на: комментарий от anonymous

сортировка слишком тормозит код в моем случае стараюсь найти способ максамально економный. Вторые максимумы делают мне более шировеи список вероятностей. поэтому нужны.

anonymous
()
Вы не можете добавлять комментарии в эту тему. Тема перемещена в архив.