Advertisement
HasteBin0

JavaScript `map` in Python

Aug 8th, 2020
1,523
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.31 KB | None | 0 0
  1. def scale(x: float, x_min: float, x_max: float, y_min: float, y_max: float) -> float:
  2.     """Give y | (x - x_min) / (x_max - x_min) == (y - y_min) / (y_max - y_min).  Also, (x_min <= x <= x_max) and (y_min <= y <= y_max).  Map() in JavaScript."""
  3.     return (x - x_min) * (y_max - y_min) / (x_max - x_min) + y_min
  4.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement