Changes between Version 3 and Version 4 of Ticket #1842, comment 5


Ignore:
Timestamp:
Sep 26, 2022, 9:43:37 AM (20 months ago)
Author:
Bang Pham Huu

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #1842, comment 5

    v3 v4  
     1NEW formula works for negative indices as well.
     2
     3{{{
     4import math
     5def scaleFloor(slo, shi, tlo, thi):
     6  scaleFactor = (shi - slo + 1) / (thi - tlo + 1)
     7  for tn in range(tlo, thi + 1):
     8    print( math.floor((tn-tlo) * scaleFactor) + slo )
     9
     10
     11# it returns the same result with: rasql -q 'SELECT encode(scale(<[-10:20] -10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20>, [-2:2]), "text/csv")' --out string
     12scaleFloor(-10, 20, -2, 2)
     13
     14}}}
     15
     16
     17
     18
     19
     20
     21
     22
     23
     24
     25----
     26
     27NOT WORK for negative indices
     28
     29
    130The formula to find the cell numbers in rasql for scaling down is:
    231