comparison python/utils.py @ 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 584613399513
children 571ba5ed22e2
comparison
equal deleted inserted replaced
239:93c26e45efd8 241:ee1caff48b03
161 161
162 162
163 ######################### 163 #########################
164 # maths section 164 # maths section
165 ######################### 165 #########################
166
167 def sortXY(X,Y):
168 'returns the sorted (x, Y(x)) sorted on X'
169 D = {}
170 for x, y in zip(X,Y):
171 D[x]=y
172 xsorted = sorted(D.keys())
173 return xsorted, [D[x] for x in xsorted]
166 174
167 def ceilDecimals(v, nDecimals): 175 def ceilDecimals(v, nDecimals):
168 '''Rounds the number at the nth decimal 176 '''Rounds the number at the nth decimal
169 eg 1.23 at 0 decimal is 2, at 1 decimal is 1.3''' 177 eg 1.23 at 0 decimal is 2, at 1 decimal is 1.3'''
170 from math import ceil,pow 178 from math import ceil,pow