Some copy/paste problems in my last post. The first use of msk to
expand v should have looked like:
   msk #inv v
0 0 20 0 0 40 0 0 0 60 80 100

Followed by use of "custom fill" to expand with infinity
   msk #inv!._ v
0 _ 20 _ _ 40 _ _ _ 60 80 100


On Tue, Nov 20, 2012 at 5:34 PM, Ric Sherlock <[email protected]> wrote:
> Not sure I totally understand the real world implications/restrictions
> that might help suggest the best solution to your problem but here are
> some ideas that may be useful...
>
>    msk=. (1 + i. >./ t) e. t   NB. use this mask to expand your vector v
> 1 0 1 0 0 1 0 0 0 1 1 1
>     msk #inv!._ v
> 0 0 20 0 0 40 0 0 0 60 80 100  NB. need to use a unique number to
> signify missings
>     ]b=: msk #inv!._ v
> 0 _ 20 _ _ 40 _ _ _ 60 80 100
>    10 20 20 30 30 30 (I. b=_)} b   NB. replace missings with your list of vals
> 0 10 20 20 20 40 30 30 30 60 80 100
>
> You can compress the above to fewer steps:
>    ]b=: v ([ #inv!._~ ] e.~ 1 + i.@(>./)@]) t
> 0 _ 20 _ _ 40 _ _ _ 60 80 100
>    newvals=: 10 20 20 30 30 30
>    newvals [`(([: I. _&=)@])`]} b
> 0 10 20 20 20 40 30 30 30 60 80 100
>
> On Tue, Nov 20, 2012 at 11:38 AM, Alexander Epifanov <[email protected]> 
> wrote:
>> Hello,
>>
>> Unfortunately cannot resolve problem, which could be easy resolved with loop:
>> t=: 1 3 6 10 11 12
>> v=: 0 20 40 60 80 100
>>
>> i=:   _1+(}.-}:) t
>> i NB. its just distance between numbers
>> 1 2 3 0 0 0
>>
>> And now the main problem for me, because I have to modify v array:
>> if i = 0 then nothing
>> if i = 1 or i = 2 then insert average value (for 1) and two values for 2
>> if i = 3 then insert previous value
>>
>> so, we have to fill missed values in t and v:
>> t=: 1   3   6 10 11  12
>> v=: 0 20 40 60 80 100
>>
>> should be:
>> t2: 1   2   3   4  5   6   7  8   9 10 11 12 (ok, its just full index now)
>> v2: 0 10 20 30 30 40 40 40 40 60 80 100
>> ^ inserted by condition: 10; 30 30; 40 40 40
>>
>> Could you please help how to resolve it better? I suppose I can rotate
>> |:t,:v and then fold it one-by-one, but I think it is not good
>> solution.
>>
>> Thank you,
>> --
>> Regards,
>>   Alexander.
>> ----------------------------------------------------------------------
>> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to