changeset 81:990a27e125f2

add distance norm function
author Jeff Hammel <k0scist@gmail.com>
date Sun, 17 Dec 2017 13:44:37 -0800
parents 3c7927f59b05
children c05ce6b7f941
files tvii/distance.py
diffstat 1 files changed, 8 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tvii/distance.py	Sun Dec 17 13:44:37 2017 -0800
@@ -0,0 +1,8 @@
+"""
+distance functions; really the `N` norm
+"""
+
+def distance(x, y, N=2):
+    assert len(x) == len(y)
+    return sum([(_x - _y)**N
+                for _x, _y in zip(x, y)])**(1./N)