# Thread: Maping a value in python

1. ## Maping a value in python

I was wondering if there was a way to map values in python. When programing the arduino there is a way to take a value and convert it into a smaller or larger value. This function for arduino is called map. After searching the web I discovered that the map function in python is used differently. Here is what an arduino map function would look like "map(val, 0, 180, 0, 90)". This would take the integer "val" which will be between 0 and 180 and convert it to a number between 0 and 90. I could not find the mathematical formula that the arduino uses to do this so my question is how can I do this in python either mathematically or using a function?

2. ## Re: Maping a value in python

From the map function documentation on Arduino.cc :
Appendix

For the mathematically inclined, here's the whole function
long map(long x, long in_min, long in_max, long out_min, long out_max)
{
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}

There are currently 1 users browsing this thread. (0 members and 1 guests)

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•