Is this what you're asking for?
# Scaler.py # def scale(OldList, NewMin, NewMax): NewRange = float(NewMax - NewMin) OldMin = min(x) OldMax = max(x) OldRange = float(OldMax - OldMin) ScaleFactor = NewRange / OldRange print '\nEquasion: NewValue = ((OldValue - ' + str(OldMin) + ') x ' + str(ScaleFactor) + ') + ' + str(NewMin) + '\n' NewList = [] for OldValue in OldList: NewValue = ((OldValue - OldMin) * ScaleFactor) + NewMin NewList.append(NewValue) return NewList x = [13, 71, 120, 88, 82, 100, 10, 65, 101, 45, 26] foo = scale(x, 0, 1.0) ##x = [.12789, .982779, .19798198, .266796, .656527, .257877091] ##foo = scale(x, 0, 127) ##x = [0, 50, 100] ##foo = scale(x, 32, 212) ##x = [32, 122, 212] ##foo = scale(x, 0, 100) print 'New List = ' + str(foo) Print >>> Equasion: NewValue = ((OldValue - 10) x 0.00909090909091) + 0 New List = [0.027272727272727271, 0.55454545454545456, 1.0, 0.70909090909090911, 0.65454545454545454, 0.81818181818181812, 0.0, 0.5, 0.82727272727272727, 0.31818181818181818, 0.14545454545454545] >>> -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of kevin parks Sent: Tuesday, March 14, 2006 1:03 AM To: tutor@python.org Subject: [Tutor] scaling values i have various functions (that i didn't write) that put out data in lists of various types. But some functions (which i didn't write) that expect the data to be scaled, sometimes 0-1 sometimes 1-2, sometimes 0-127..., sometimes 0 - 32768... gosh you name it. In other words i have a bunch of black boxes that don't speak the same language .... is there a scaling function in python (or numeric or scipy) that can scale a list of values to a high precision? x = [13, 71, 120, 88, 82, 100, 10, 65, 101, 45, 26] foo = scale(x, 0, 1.0) and get that list scaled 0 to 1, or if i had: x = [.12789, .982779, .19798198, .266796, .656527, .257877091] foo = scale(x, 0, 127) cheers, -kp-- _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor