[Jprogramming] Rescale data
Raul Miller
rauldmiller at gmail.com
Mon Sep 20 23:42:36 HKT 2010
On Mon, Sep 20, 2010 at 11:08 AM, Devon McCormick <devonmcc at gmail.com> wrote:
> scaleNums=: 3 : 0
> 0 1 scaleNums y
> :
> 'low hi'=. ((<./),>./)x
> if. 0 *./ . = 11 o. ,y do.
> nums=. y-<./,y
> nums=. nums%>./,nums NB. scale from 0 to 1
> else.
> nums=. y-<./10 o. ,y
> nums=. nums%>./10 o. ,nums NB. scale from 0 to 1 for complex
> end.
> nums=. low+nums*hi-low
> )
>
> It could be terser but I wrote it quite a while ago.
If you want terser, I would be tempted to do something like this:
scaleNums=:3 :0
0 1 scaleNums y
:
'lowX magX lowY magY'=.x ,&(-~/\@(<./,>./)),10 o.y
lowX+magX*(y-lowY)%magY
)
--
Raul
More information about the Programming
mailing list