From 243783086ec1f7336e41cabbef38a4958de3cc3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Hanu=C5=A1?= Date: Tue, 2 Feb 2021 09:57:37 +0100 Subject: [PATCH] List comprehension improves speed of KNN query --- examples/pyw_hnswlib.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/examples/pyw_hnswlib.py b/examples/pyw_hnswlib.py index dc300173..e450aa15 100644 --- a/examples/pyw_hnswlib.py +++ b/examples/pyw_hnswlib.py @@ -55,8 +55,7 @@ def knn_query(self, data, k=1): labels_int, distances = self.index.knn_query(data=data, k=k) labels = [] for li in labels_int: - line = [] - for l in li: - line.append(self.dict_labels[l]) - labels.append(line) + labels.append( + [self.dict_labels[l] for l in li] + ) return labels, distances