Distances in python
Project description
Space with a (pseudo-)metric allows us to perform distances. This library offers several functionalities in this regard;
How to install
We run the command on desired installation environment:
pip install spycio
Minimal example
#!/usr/bin/env python
from numpy import Inf
from math import pi
from spycio import distance, travelTime
def format_distance_without_configuration(A, B, speed, method):
string_template='A:{origin}, B:{target}, speed:{speed}, method:{on}, distance:{d}, eta:{eta}'
dist=distance(A, B, method)
duration=travelTime(speed, A, B, method)
return string_template.format(origin=A,target=B,speed=speed, on=method,d=dist,eta=duration)
def format_distance(A, B, speed, method, config):
string_template='A:{origin}, B:{target}, speed:{speed}, method:{on}, config:{setup}, distance:{d}, eta:{eta}'
dist=distance(A, B, method, config)
duration=travelTime(speed, A, B, method, config)
return string_template.format(origin=A,target=B, speed=speed, on=method,setup=config, d=dist, eta=duration)
# Default distance calculation: Euclidean
A=[0, 0]
B=[1, 1]
speed=1
print('Euclidean distance: '+str(distance(A, B)))
print('\n')
configurations=[
([1, 1], [2, 2], speed, "manhattan"),
([1, 1], [2, 2], speed, "euclidean"),
([1, 1], [2, 2], speed, "max")
]
print('Format distance without configuration: ')
for A, B, speed, method in configurations:
print(format_distance_without_configuration(A, B, speed, method))
print('\n')
configurations=[
([1, 1], [2, 2], speed, "pnorm", { "exponent": 2 }),
([1, 1], [2, 2], speed, "pnorm", { "exponent": 3 }),
([1, 1], [2, 2], speed, "pnorm", { "exponent": 4 }),
([1, 1], [2, 2], speed, "pnorm", { "exponent": Inf }),
([0, 0], [pi / 2, 0], speed, "sphere", { "radius": 1 })
]
print('Format distance with configuration: ')
for A, B, speed, method, config in configurations:
print(format_distance(A, B, speed, method, config))
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
spycio-0.2.5.tar.gz
(10.1 kB
view details)
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
spycio-0.2.5-py3-none-any.whl
(10.0 kB
view details)
File details
Details for the file spycio-0.2.5.tar.gz.
File metadata
- Download URL: spycio-0.2.5.tar.gz
- Upload date:
- Size: 10.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.4.1 CPython/3.8.10 Linux/5.15.0-69-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
896b133c1889af69b8ad495f540cd16d63ef99e48ef02527960f43d3fcf8e48d
|
|
| MD5 |
232875df84f0b8fd40c926b21c3236f8
|
|
| BLAKE2b-256 |
8c59e75047971eab5cada7c180e5ef0293b9bb8e2522caa8781e09c051192bac
|
File details
Details for the file spycio-0.2.5-py3-none-any.whl.
File metadata
- Download URL: spycio-0.2.5-py3-none-any.whl
- Upload date:
- Size: 10.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.4.1 CPython/3.8.10 Linux/5.15.0-69-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7c1b75e6330f6bfb1a651d27abab4cc45c8719a3d2699d887b8cd8678aa5ef87
|
|
| MD5 |
236cb674ae67607f6f48b564df398c7d
|
|
| BLAKE2b-256 |
a7ed81732ed8a6d7867e37aa6538770a94a5e403088a9d6fe0c7587d244f744a
|