prefix=: (>[EMAIL PROTECTED]: }. i.)@[ {.&.> <@]
suffix=: |.&.>@prefix&.|.
sw =: prefix , <\ , suffix
----- Original Message -----
From: Roger Hui <[EMAIL PROTECTED]>
Date: Tuesday, January 30, 2007 6:53 pm
Subject: Re: [Jprogramming] sliding window
> prefix=: 4 : '(->:i.-<.x%2)}.&.> < x {.y'
> suffix=: 4 : '( >:i. <.x%2)}.&.> <(-x){.y'
> sw=: prefix , <\ , suffix
>
> d=: 5 10 7 8 9 2 1 100 _1 4 3
> z=: 5 10 7; 5 10 7 8; 5 10 7 8 9; 10 7 8 9 2; 7 8 9 2 1; 8 9 2 1
> 100; 9 2 1 100 _1; 2 1 100 _1 4; 1 100 _1 4 3; 100 _1 4 3; _1 4 3
>
> z -: 5 sw d
> 1
>
> I am not sure what is supposed to happen if n
> is greater than the length of the data.
>
> The order of the arguments is switched based on the
> principle used for J primitive dyads: x&func is
> expected to be a more useful function than func&y .
>
>
>
> ----- Original Message -----
> From: June Kim <[EMAIL PROTECTED]>
> Date: Tuesday, January 30, 2007 5:39 pm
> Subject: [Jprogramming] sliding window
>
> > Suppose the following data is given
> >
> > d=: 5 10 7 8 9 2 1 100 _1 4 3
> >
> > Now suppose a verb that moves a sliding window through the data
> >
> > d sw 5
> >
> > The size of the window is always odd. For each item in the given
> data,> the window should locate it at the middle point of the
> window. For
> > some items that's nearby boundaries, the window size could be
> smaller> than the given.
> >
> > The result should be
> >
> > 5 10 7; 5 10 7 8; 5 10 7 8 9; 10 7 8 9 2; 7 8 9 2 1; 8 9 2 1
> 100;
> > 9 2
> > 1 100 _1; 2 1 100 _1 4; 1 100 _1 4 3; 100 _1 4 3; _1 4 3
> >
> > Middle points for the window are 5, 10, 7 ..., 4, 3
> >
> > What is an easy way for sw?
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm