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(
    items,
    distance_fn,
)
neighbours = nn.run()
print(list(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 details)

Uploaded Source

Built Distribution

neatnearestneighbour-1.0.0-py3-none-any.whl (15.4 kB view details)

Uploaded Python 3

File details

Details for the file neatnearestneighbour-1.0.0.tar.gz.

File metadata

  • Download URL: neatnearestneighbour-1.0.0.tar.gz
  • Upload date:
  • Size: 2.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2

File hashes

Hashes for neatnearestneighbour-1.0.0.tar.gz
Algorithm Hash digest
SHA256 d6fd622ef2c8cb3b6a755cbccc3a8a1077dd187b733fb91cb878886e32aede25
MD5 2889bff0dd2a40f370d07dd47998a271
BLAKE2b-256 7d4f855094491e14558d59ab369d9f0c7c5386d58e831be0c20a2b762f9d782b

See more details on using hashes here.

File details

Details for the file neatnearestneighbour-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: neatnearestneighbour-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 15.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2

File hashes

Hashes for neatnearestneighbour-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e2aa6114641671c014b3a56de516ab25bf870d0f345f3c00d61fc7ccc3051c89
MD5 6d9d8849549b27413df1a7d02564f35b
BLAKE2b-256 8c2869b16d87f4029c894d08734cdc9af5379780aaf2fb5fe66262ab756e6b27

See more details on using hashes here.

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