From 38a39d685774ecd6feec77cf0196822ca1d9bc5e Mon Sep 17 00:00:00 2001 From: "philippot.m" <> Date: Fri, 16 May 2025 14:29:46 +0200 Subject: [PATCH] =?UTF-8?q?Toutes=20les=20fonction=20sont=20op=C3=A9ration?= =?UTF-8?q?nel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- k_plus_proche.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/k_plus_proche.py b/k_plus_proche.py index 4688802..701aa38 100644 --- a/k_plus_proche.py +++ b/k_plus_proche.py @@ -11,16 +11,17 @@ def kPlusProche(point,lst_representative): Une liste triée en fonction de la distance dont les éléments sont des tuples (distance, indice du tableau original)""" voisins = [] for i in range(len(lst_representative)): - d = distance(point, lst_representative[i] ) + d = distance (point, lst_representative[i] ) voisins.append((d, i)) voisins.sort() # Pour un couple, sort trie d'abord en fonction de la première valeur, donc la distance return voisins -def PuissanceMoyenne(lst_trie): +def PuissanceMoyenne(lst_trie,k,lst_ref): somme=0 - if k > len(lst_tri): + if k > len(lst_trie): k = len(lst_trie) for i in range(0,k): - somme=somme+lst_ref(lst_trie[i](1)) + somme=somme+lst_ref[lst_trie[i][1]][1] return somme/k - \ No newline at end of file +lst_trie=kPlusProche((1,2,6),[(1,5,9,8),(9,6,2,8),(3,5,6,42)]) +PuissanceMoyenne(lst_trie,1,[((1,5,9),8),((9,6,2),8),((3,5,6),42)]) \ No newline at end of file