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]
Metadata
Release files for neatnearestneighbour 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| neatnearestneighbour-1.0.0.tar.gz | 2.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| neatnearestneighbour-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 17.9 kB
Release files / neatnearestneighbour-1.0.0.tar.gz
| Download URL | neatnearestneighbour-1.0.0.tar.gz |
|---|---|
| Size | 2.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d6fd622ef2c8cb3b6a755cbccc3a8a1077dd187b733fb91cb878886e32aede25
|
|
BLAKE2b-256 checksum How to use checksums |
7d4f855094491e14558d59ab369d9f0c7c5386d58e831be0c20a2b762f9d782b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Release files / neatnearestneighbour-1.0.0-py3-none-any.whl
| Download URL | neatnearestneighbour-1.0.0-py3-none-any.whl |
|---|---|
| Size | 15.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e2aa6114641671c014b3a56de516ab25bf870d0f345f3c00d61fc7ccc3051c89
|
|
BLAKE2b-256 checksum How to use checksums |
8c2869b16d87f4029c894d08734cdc9af5379780aaf2fb5fe66262ab756e6b27
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|