I was drafting this before Oleg's reply arrived. It's slightly
different from his, and shows a derivation of a tacit form.
==============================================================
Is this the sort of thing you need?
Consider:
d
10 7 5 6 7 1 9 8 2 4
(1 , 2 >/\ ])d NB. boolean for = left > right for each pair ?
1 1 1 0 0 1 0 1 1 0
1 1 1 0 0 1 0 1 1 0 < ;. 1 d NB. partition d by this boolean
+--+-+-----+---+-+---+
|10|7|5 6 7|1 9|8|2 4|
+--+-+-----+---+-+---+
1 1 1 0 0 1 0 1 1 0(<&(<./\);. 1)d NB. required work in boxes
+--+-+-----+---+-+---+
|10|7|5 5 5|1 1|8|2 2|
+--+-+-----+---+-+---+
1 1 1 0 0 1 0 1 1 0 ;@(<&(<./\);. 1)d NB. unbox
10 7 5 5 5 1 1 8 2 2
((1,2>/\]);@(<&(<./\);. 1)])d NB. tacit form
10 7 5 5 5 1 1 8 2 2
(;@(<&(<./\);. 1)~1,2>/\])d NB. tacit avoiding one "]"
10 7 5 5 5 1 1 8 2 2
Mike
Mikl Kurkov wrote:
I need function that for each value in vector return this value if
previous was bigger and return closest minimum if previous data is
lesser.
Examlpe:
d =: 10 7 5 6 7 1 9 8 2 4 NB. data
r =: 10 7 5 5 5 1 1 8 2 2 NB. result
NB. What I have now is
fn1 =: ({:@])`[ @. ( [ < [EMAIL PROTECTED])
fn2 =: [ , [EMAIL PROTECTED] , fn1
fn =: (}. @: (fn2/) @:(,{:)@: |.) f.
r -: fn d
1
But it realy slow and I think it could be optimized.
So what would you suggest?
Thanks in advance.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm