1 """
2 This module provides code for various distance measures.
3
4 Functions:
5 euclidean Euclidean distance between two points
6 euclidean_py Pure Python implementation of euclidean.
7
8 """
9
10 import math
11 try:
12 from Numeric import *
13 except ImportError, x:
14 raise ImportError, "This module requires Numeric (precursor to NumPy)"
15
16 from Bio import listfns
17
19 """euclidean(x, y) -> euclidean distance between x and y"""
20 if len(x) != len(y):
21 raise ValueError, "vectors must be same length"
22
23
24 d = x-y
25 return sqrt(dot(d, d))
26
28 """euclidean_py(x, y) -> euclidean distance between x and y"""
29
30
31
32 if len(x) != len(y):
33 raise ValueError, "vectors must be same length"
34 sum = 0
35 for i in range(len(x)):
36 sum += (x[i]-y[i])**2
37 return math.sqrt(sum)
38
39
40
41 try:
42 from cdistance import *
43 except ImportError:
44 pass
45