Last change
on this file since 7876 was
2552,
checked in by jack, 18 years ago

Convenience functions for common norms.

File size:
448 bytes

Line  

1  """Definitions of common norm functions, for consistency checks. 

2  """ 

3  

4  from math import fabs,sqrt 

5  

6  def l1_norm(vector): 

7  """L_1 norm of a vector""" 

8  return reduce(lambda p,q : p + q, map(fabs, vector), 0.0) 

9  

10  def l2_norm(vector): 

11  """L_2 norm of a vector""" 

12  return sqrt(reduce(lambda p,q : p + q, map(lambda x : x ** 2, vector), 0.0)) 

13  

14  def linf_norm(vector): 

15  """L_\infty norm of a vector""" 

16  return max(map(fabs, vector + [0.0])) 

Note: See
TracBrowser
for help on using the repository browser.