Skip to main content

Distances in python

Project description

apartogether

Version python downloads Binder

codecov Lint workflow

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


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.6.tar.gz (10.1 kB view details)

Uploaded Source

Built Distribution

spycio-0.2.6-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

Details for the file spycio-0.2.6.tar.gz.

File metadata

  • Download URL: spycio-0.2.6.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

Hashes for spycio-0.2.6.tar.gz
Algorithm Hash digest
SHA256 16dfd069e76d2c78aa67536e5d71bd36c4a024c5534872dc32cf107c7bc84f55
MD5 08730a63cc994d85d155b46555275e17
BLAKE2b-256 cc9fb9af584b7456bf16ddebe5daf2175463108b221167c22f1ef35b42f0f9cd

See more details on using hashes here.

File details

Details for the file spycio-0.2.6-py3-none-any.whl.

File metadata

  • Download URL: spycio-0.2.6-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

Hashes for spycio-0.2.6-py3-none-any.whl
Algorithm Hash digest
SHA256 8c4952f4e75b5816394110d87d67f36450a84207a49738a7b63bcd828d0e438e
MD5 8b4fda62b177fbc4fff88bdbefafac13
BLAKE2b-256 e2e268d3bd70317f47663fdb4ae9c95e96f0d822da84d7b574a6543aaf592264

See more details on using hashes here.

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