Changes between Version 3 and Version 4 of Ticket #1842, comment 5
- Timestamp:
- Sep 26, 2022, 9:43:37 AM (2 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #1842, comment 5
v3 v4 1 NEW formula works for negative indices as well. 2 3 {{{ 4 import math 5 def 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 12 scaleFloor(-10, 20, -2, 2) 13 14 }}} 15 16 17 18 19 20 21 22 23 24 25 ---- 26 27 NOT WORK for negative indices 28 29 1 30 The formula to find the cell numbers in rasql for scaling down is: 2 31