Closest Pairs 📐
Find the closest pairs in an array.
Getting Started
pip install closest_pairs
or install from source:
git clone https://github.com/justinshenk/closest-pairs
cd closest_pairs
pip install .
How to use
import closest_pairs
# X is an n x m numpy array
pairs, distances = closest_pairs.solve(X, n=1)
You can specify how many pairs you want to identify with n.
Example
import closest_pairs
import numpy as np
import matplotlib.pyplot as plt
# Create dataset
X = np.random.random((100,2))
pairs, distance = closest_pairs.solve(X, n=1)
# Plot points
z, y = np.split(X, 2, axis=1)
fig, ax = plt.subplots()
ax.scatter(z, y)
for i, txt in enumerate(X):
if i in pairs:
ax.annotate(i, (z[i], y[i]), color='red')
else:
ax.annotate(i, (z[i], y[i]))
Check pairs:
In [10]: pairs
Out[10]:
array([[[ 7],
[16]],
[[96],
[50]]])
Output:
Caveats
closest_pairs will reduce the dimensionality with PCA of your data to two-dimensions for faster processing.
It also removes the first point in a pair if n>1. In rare cases this leads to false negatives if the data is highly overlapping.
Credit and Explanation
Python code modified from Andriy Lazorenko, packaged and made useful for >2 features by Justin Shenk.
Metadata
Release files for closest-pairs 0.1.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| closest_pairs-0.1.5.tar.gz | 4.0 kB | Without provenance | Details for closest_pairs-0.1.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| closest_pairs-0.1.5-py3-none-any.whl | Python 3 | none | any | Details for closest_pairs-0.1.5-py3-none-any.whl |
Total release size: 8.7 kB
Release files / closest_pairs-0.1.5.tar.gz
| Download URL | closest_pairs-0.1.5.tar.gz |
|---|---|
| Size | 4.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7f6d3e8834aa0979e86db16cc1d442c47bbb9a71f5348173aa3563687cfb4f5e
|
|
BLAKE2b-256 checksum How to use checksums |
458045956b4ef04984d3397037d9304da2aa559874ded2216087c344fff3d895
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2
|
Release files / closest_pairs-0.1.5-py3-none-any.whl
| Download URL | closest_pairs-0.1.5-py3-none-any.whl |
|---|---|
| Size | 4.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cc5c2900761931f962c459655e72e1415d3da76c44c8dc399625799aca33059c
|
|
BLAKE2b-256 checksum How to use checksums |
c2c29b75f8b78dae9ebd9e8e697c28b4de0097f70640c6ffb3ce03cace188c28
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2
|
Security for closest-pairs 0.1.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.