2007/1/31, ramacd <[EMAIL PROTECTED]>:
June;
Not to diminish Roger's solution, but what should
7 sw d
be? If it is indeed what Roger's sw gives, that's all well and good, but if
Yes, Roger's sw gives the result I expect. The windows middle(center
point) moves one by one to the right, starting from index 0 to the
last index, the size of the window being elastic(when crossing the
boundary).
Here is my sw:
ft=:[+i.@>:@(]-[)
wing=:-:@<:
mw=:([EMAIL PROTECTED]) ft ([EMAIL PROTECTED])
st=:] {~ [ #~ (0 <: [) *. [ < [: # ]
sw=:[ <@st~"1 [: ] ] mw [: i. [: # [
I am not satisfied with it, especially its verbosity, though.
it isn't, perhaps there's more to this problem.
------------------------------------------------------------------------
|\/| Randy A MacDonald | APL: If you can say it, it's done.. (ram)
|/\| [EMAIL PROTECTED] |
|\ | | The only real problem with APL is that
BSc(Math) UNBF'83 | it is "still ahead of its time."
Sapere Aude | - Morten Kromberg
Natural Born APL'er | Demo website: http://156.34.82.188/
-----------------------------------------------------(INTP)----{ gnat }-
----- Original Message -----
From: "Roger Hui" <[EMAIL PROTECTED]>
To: "Programming forum" <[email protected]>
Sent: Tuesday, January 30, 2007 10: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
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm