I don't understand the lambda k function, and especially, what is the last [k] in this line of code?
sorting_permutation = sorted(range(len(prediction_test[0:m_test])), key=lambda k: prediction_test[0:m_test][k])
I am so sorry for my English.
I don't understand the lambda k function, and especially, what is the last [k] in this line of code?
sorting_permutation = sorted(range(len(prediction_test[0:m_test])), key=lambda k: prediction_test[0:m_test][k])
I am so sorry for my English.
Copyright © 2021 Jogjafile Inc.
We should analyse the whole function. You want to sort
range(len(prediction_test[0:m_test])). Assumingm_testisn't greater thanlen(prediction_test), this should give a list containing numbers from0tom_test-1.Key parameter of sorting function defines the function that the list is accordingly sorted.
kvalues are the elements of the list that you want to sort. In your code,kwill take values0,1,2...,m_test-1under the assumption. Withprediction_test[0:m_test][k]you first take a slice of prediction_test from index0to indexm_test, then you take the element atkth index.In a nutshell,
key=lambda k: prediction_test[0:m_test][k]means that you will sort your list according to results ofprediction_test[0:m_test][k]where k will take values of your elements in the list. Your code is probably used for sorting the indices of a list according to values that they store.