Python Forum
Mapping a value to an interval
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Mapping a value to an interval
#11
(Mar-17-2023, 07:37 PM)Gribouillis Wrote:
(Mar-17-2023, 07:06 PM)JazonKuer Wrote: For a scale of 5000 it will either end on 0000, 2500, 5000, or 7500.
Only replace 100 by 500 in the interval() function. However what are the valid values when the scale is 4000 ?
73874 (71500, 76500) 919227 (916500, 921500) 448634 (446000, 451000) 196040 (193500, 198500) 767177 (764500, 769500) 972937 (970500, 975500) 146383 (144000, 149000) 345814 (343500, 348500) 685618 (683000, 688000) 578875 (576500, 581500)

No that doesn't cut it either, e.g.: 269361 (267000, 272000). I would have expected that coordinate to return (267500,272500). For a scale of 4000, here are some valid intervals: (260000,264000), (262000,266000), (264000,268000).
Reply
#12
(Mar-17-2023, 07:42 PM)JazonKuer Wrote: No that doesn't cut it either
I think you could simply take the rounding precision equal to scale.
def interval(coord, scale): u = rounding(scale, coord) m = u + scale // 2 return (2 * u - m, m)
Output:
753440 (752500, 757500) 438123 (437500, 442500) 912444 (907500, 912500) 780151 (777500, 782500) 173878 (172500, 177500) 398415 (397500, 402500) 4882 (2500, 7500) 177479 (172500, 177500) 714674 (712500, 717500) 885073 (882500, 887500)
And with a scale of 4000
Output:
844886 (842000, 846000) 946284 (946000, 950000) 413177 (410000, 414000) 69355 (66000, 70000) 172377 (170000, 174000) 328100 (326000, 330000) 871511 (870000, 874000) 428165 (426000, 430000) 649193 (646000, 650000) 496116 (494000, 498000)
Reply
#13
Here is my last word
__version__ = '2023.03.17.2' def rounding(precision, value): y = 0.5 if value >= 0 else -0.5 return precision * int(y + value / precision) def interval(coord, scale): s = scale // 2 u = rounding(s, coord) return (u - s, u + s) if __name__ == '__main__': from random import randint for i in range(10): x = randint(0, 1000000) print(x, interval(x, 5000))
Output:
589802 (587500, 592500) 886897 (885000, 890000) 775585 (772500, 777500) 17445 (15000, 20000) 794528 (792500, 797500) 57525 (55000, 60000) 466087 (462500, 467500) 501046 (497500, 502500) 906234 (902500, 907500) 744038 (742500, 747500)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  asyncio interval bigal 8 2,201 Mar-28-2025, 05:49 PM
Last Post: snippsat
  access is denied error 5 for network drive mapping ? ahmedbarbary 2 3,614 Aug-17-2022, 10:09 PM
Last Post: ahmedbarbary
  Confidence interval after doing penalised cox regression HatemAli 0 1,951 Feb-23-2022, 11:02 PM
Last Post: HatemAli
  Mapping a range ebolisa 5 7,412 Jun-12-2021, 11:17 PM
Last Post: ebolisa
  Complex X Tick Interval JoeDainton123 0 2,308 Oct-05-2020, 07:27 PM
Last Post: JoeDainton123
  mapping joystick axis to specific 'channels' in python DashOrion 1 4,598 Jul-07-2020, 04:26 PM
Last Post: DashOrion
  Updating a matrix in a time interval inside a for loop vp1989 4 4,925 May-17-2020, 07:15 PM
Last Post: vp1989
  Assigning Data from one column to another with different associated timing interval alexafshari 1 2,972 Apr-30-2020, 03:59 PM
Last Post: pyzyx3qwerty
  adddate interval in python Steve42 2 3,576 Apr-16-2020, 08:24 PM
Last Post: Larz60+
  mapping-camera-coordinates-to-a-2d-floor-plan fauveboyxuuki 0 3,840 Dec-10-2019, 10:34 PM
Last Post: fauveboyxuuki

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020
This forum uses Lukasz Tkacz MyBB addons.
Forum use Krzysztof "Supryk" Supryczynski addons.