P.S. if you want to avoid boxing (for speed):

   ($old)$(,new) (($old) #. ($new) #: i.$,new)} ,old
1 1 1 0
1 1 1 0
1 1 1 0
0 0 0 0
   ($old)$(,new) (($old) #. 0 1+"1 ($new) #: i.$,new)} ,old
0 1 1 1
0 1 1 1
0 1 1 1
0 0 0 0

Thanks,

-- 
Raul

On Tue, Oct 21, 2014 at 1:24 PM, Raul Miller <[email protected]> wrote:
>    new=:3 3$1
>    old=:4 4$0
>
>    new (($new) <@#: i.$new)} old
> 1 1 1 0
> 1 1 1 0
> 1 1 1 0
> 0 0 0 0
>
>    new (($new) <@(0 1&+)@#: i.$new)} old
> 0 1 1 1
> 0 1 1 1
> 0 1 1 1
> 0 0 0 0
>
> You can replace the 0 1 with any valid coordinate for the upper left corner.
>
> You can either make this an explicit definition, or you can build up
> an expression using a gerund to where } places the data.
>
> If you want to go the gerund route, see also:
>
> http://www.jsoftware.com/help/dictionary/d530n.htm
> http://www.jsoftware.com/jwiki/Vocabulary/curlyrt#dyadic
>
> ... and then (a) build up an expression that works and then (b) find
> good ways to name significant parts of that expression.
>
> But for amend it's often simpler to use explicit definitions - also
> there's a mild space efficiency hack in the language which favors
> explicit contexts for amend. (Search for the word "special" on that
> jwiki vocabulary page for a brief mention of this issue).
>
> Is that enough to get you started?
>
> Thanks,
>
> --
> Raul
>
>
> On Tue, Oct 21, 2014 at 10:04 AM, Sebastian <[email protected]> wrote:
>> Hello,
>>
>> I have a question similar to the question I had a few weeks before. The
>> question was how replace single values from a matrix
>> (http://jsoftware.com/pipermail/programming/2014-September/039225.html). Now
>> I would like to replace a matrix with at least 2 dimensions with values from
>> a 2 dimensional array.
>>
>> The new values should replace the old values from the matrix, like this:
>>
>> new data:
>> 1 1 1
>> 1 1 1
>> 1 1 1
>>
>> old data:
>> 0 0 0 0
>> 0 0 0 0
>> 0 0 0 0
>> 0 0 0 0
>>
>> result:
>>
>> 1 1 1 0
>> 1 1 1 0
>> 1 1 1 0
>> 0 0 0 0
>>
>> The insert position to the matrix should be parameterisable.
>>
>> Best regards
>> Sebastian
>> ----------------------------------------------------------------------
>> 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