average - python: plotting numbers as a custom range -
i'm not sure how word it, want want make 3 sets of number equivalent range of 0 10 i can call later.
for example, if have numbers 2, 4, , 9, want 2 represents 0, 4 5, , 9 10. way if write command says "call number represents 2.5", gives me 3. more examples:
0=2, 2.5=3, 5=4, 7.5=6.5, 10=9
and want after have set these numbers, can call within custom range of 2-9 saying part of scale want (like want value represents 1.25). there way in python...?
ps: i'm sorry if question exists, don't know sort of thing called.
edit: understand more of want do, i'm trying set thing script in maya (3d program), , have set of curves. right have script written smooth out jagged curves taking averages of 3 points , replacing average middle number. want rather taking average, able have input of value 0-10 controls how curve smooths out. if have curve have 2 6 , 4 on y, instead of making middle number 3.667 (the average of 3 values), want @ 4 or 3.25, or other average. want 0-10 system controls how number decreases. hope makes sense.......
for 3 points, can define quadratic curve fits them.
so example, modifying code vb helper page, get
def fit(p1, p2, p3): """return quadratic function fits 3 points p1, p2, p3, each defined tuple of (x,y) coordinates""" = ((p2[1]-p1[1])*(p1[0]-p3[0]) + (p3[1]-p1[1])*(p2[0]-p1[0])) / \ ((p1[0]-p3[0])*(p2[0]**2-p1[0]**2) + (p2[0]-p1[0])*(p3[0]**2-p1[0]**2)) b = ((p2[1]-p1[1]) - a*(p2[0]**2 - p1[0]**2)) / (p2[0]-p1[0]) c = p1[1] - a*p1[0]**2 - b*p1[0] return lambda x: a*x**2 + b*x + c
will give function can use (in python 3) follows:
>>> f = fit((0,2), (5,4), (10,9)) >>> f(2) 2.44 >>> f(100) 612.0 >>> f(4) 3.36 >>> f(5) 4.0 >>> f(9) 7.760000000000001
in python 2, need call floats explicitly:
>>> f = fit((0.0,2.0), (5.0,4.0), (10.0,9.0))
Comments
Post a Comment