Mapping a value in python: Difference between revisions

From XPUB & Lens-Based wiki
(Created page with " <source lang="python"> def map (v, inlow, inhigh, outlow, outhigh): p = (float(v) - inlow) / inhigh return outlow + (p * (outhigh - outlow)) </source>")
 
No edit summary
 
Line 5: Line 5:
     return outlow + (p * (outhigh - outlow))
     return outlow + (p * (outhigh - outlow))
</source>
</source>
Example: Maps the input value 50 from an input range of 0 - 100 to an output range of 2000 and 3000.
  map(50, 0, 100, 2000, 3000)
  Out[2]: 2500.0

Latest revision as of 12:06, 20 March 2017

def map (v, inlow, inhigh, outlow, outhigh):
    p = (float(v) - inlow) / inhigh
    return outlow + (p * (outhigh - outlow))

Example: Maps the input value 50 from an input range of 0 - 100 to an output range of 2000 and 3000.

 map(50, 0, 100, 2000, 3000)
 Out[2]: 2500.0