Skip to main content

A nearest neighbour algorithm written in pure Python.

Project description

A Nearest Neighbour algorithm written in pure python. The intention is to use this package with PyPy. The hot loop in the algorithm are perfect for PyPy's just-in-time compilation and results in fast performance.

To run create an instance of NearestNeighbour and call run(). The output is a generator of items in order by finding the next nearest neighbour of each item. The starting item is randomized.

The input items can be a list of anything, because the distance function also has to be provided. The distance function must be able to calculate the distance between any items in the input list.

An example:

from neatnearestneighbour import NearestNeighbour
items = [10, 20, 15, 5, 100, 2, 30, 50]
distance_fn = lambda a, b: abs(b - a)

nn = NearestNeighbour(
neighbours =
# [50, 30, 20, 15, 10, 5, 2, 100]

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

neatnearestneighbour-1.0.0.tar.gz (2.5 kB view hashes)

Uploaded source

Built Distribution

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page