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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d6fd622ef2c8cb3b6a755cbccc3a8a1077dd187b733fb91cb878886e32aede25
|
|
| MD5 |
2889bff0dd2a40f370d07dd47998a271
|
|
| BLAKE2b-256 |
7d4f855094491e14558d59ab369d9f0c7c5386d58e831be0c20a2b762f9d782b
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e2aa6114641671c014b3a56de516ab25bf870d0f345f3c00d61fc7ccc3051c89
|
|
| MD5 |
6d9d8849549b27413df1a7d02564f35b
|
|
| BLAKE2b-256 |
8c2869b16d87f4029c894d08734cdc9af5379780aaf2fb5fe66262ab756e6b27
|