n-Dimensional Fit Function
eharetea

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(xyzcoord):
  zip(*xyz)
  z.append(coord)
  return zip(*xyz)


## averages to sets of points
def avgPts(xyz1xyz2):
  return [n/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(valueoldminoldmaxnewminnewmax):
  lambda x1.000 x
  (valueoldminoldmaxnewminnewmax) = map(l, (valueoldminoldmaxnewminnewmax))
  if (value <= oldmin):
    return newmin
  if (value >= oldmax):
    return newmax
  value = ((value oldmin) / (oldmax oldmin)) * (newmax-newmin) + newmin
  return value

def fitzip(zippedListminsmaxes):
  ListOfLists = []
  for list, newMinnewMax in zip(zippedListminsmaxes):
      origMin min(list);
      origMax max(list);
      newList = []
      for item in list:
          newList.append(fit(itemorigMinorigMaxnewMinnewMax))
      ListOfLists.append(newList)
  return ListOfLists






Downloads:
Download: points.py 1 KB

Please login or Click Here to register for downloads
Creative Commons License
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