changeset 241:ee1caff48b03

added function to sort to list of paired data X,Y
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Wed, 11 Jul 2012 16:47:49 -0400
parents 93c26e45efd8
children 942455aff829
files python/utils.py
diffstat 1 files changed, 8 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/python/utils.py	Wed Jul 11 16:30:23 2012 -0400
+++ b/python/utils.py	Wed Jul 11 16:47:49 2012 -0400
@@ -164,6 +164,14 @@
 # maths section
 #########################
 
+def sortXY(X,Y):
+    'returns the sorted (x, Y(x)) sorted on X'
+    D = {}
+    for x, y in zip(X,Y):
+        D[x]=y
+    xsorted = sorted(D.keys())
+    return xsorted, [D[x] for x in xsorted]
+
 def ceilDecimals(v, nDecimals):
     '''Rounds the number at the nth decimal
     eg 1.23 at 0 decimal is 2, at 1 decimal is 1.3'''