This python program fits n-Dimensional data.
Fit n-Dimensions of data into a specified range.
Date Created:Monday February 23rd, 2009 08:07 PM
Date Modified:Monday February 23rd, 2009 10:53 PM
#
# Author: Dan Lynch
#
## xyz [x,y,z] where x,y,z are lists of numbers
## coords (a,b,c) where a,b,c are numbers
def addPt(xyz, coord):
z = zip(*xyz)
z.append(coord)
return zip(*xyz)
## averages to sets of points
def avgPts(xyz1, xyz2):
return [n/2 for n in map(lambda list: list[0] + list[1], zip(xyz1,xyz2))]
# computes the centroid!
def centroid(x,y,z):
def c(s):
sum = 0
for i in s:
sum += i
return sum/len(s)
return [c(x),c(y),c(z)]
# fitzip will fit n-Dimensional coordinates
# requires input of 3 n-element sized lists: the list of coords,
# and respective min and maximum value lists
def fit(value, oldmin, oldmax, newmin, newmax):
l = lambda x: 1.000 * x
(value, oldmin, oldmax, newmin, newmax) = map(l, (value, oldmin, oldmax, newmin, newmax))
if (value <= oldmin):
return newmin
if (value >= oldmax):
return newmax
value = ((value - oldmin) / (oldmax - oldmin)) * (newmax-newmin) + newmin
return value
def fitzip(zippedList, mins, maxes):
ListOfLists = []
for list, newMin, newMax in zip(zippedList, mins, maxes):
origMin = min(list);
origMax = max(list);
newList = []
for item in list:
newList.append(fit(item, origMin, origMax, newMin, newMax))
ListOfLists.append(newList)
return ListOfLists
Downloads:
Download: points.py 1 KB
Please login or Click Here to register for downloads
n-Dimensional Fit Function by Dan Lynch
is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License
Based on a work at www.3daet.com
Permissions beyond the scope of this license may be available at http://www.3daet.com
