Skip to main content

closest_pairs finds the closest pairs of points in a dataset

Project description

Closest Pairs

Find the closest pair in a dataset.

Getting Started

pip install closest_pairs

How to use

import closest_pairs

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

X = np.random.random((100,2))
pairs, distance = closest_pairs.solve(X, n=1)

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: example_plot

Credit

Python code modified from Andriy Lazorenko, packaged by Justin Shenk.

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

closest_pairs-0.1.0.tar.gz (3.7 kB view hashes)

Uploaded Source

Built Distribution

closest_pairs-0.1.0-py3-none-any.whl (4.5 kB view hashes)

Uploaded Python 3

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