Much simpler even: T (*"1 0"_ 1 |:) >:i.3 4
which leads to (1 0,: 0 1) (*"1 0"_ 1 |:) arr1,:arr2 R.E. Boss -----Original Message----- From: Programming <[email protected]> On Behalf Of R.E. Boss Sent: zondag 9 augustus 2020 11:05 To: [email protected] Subject: Re: [Jprogramming] Constructing arrays by filling "templates" My solution is a quick hack and, I suppose, not easy to generalize. Given a template [T=:_3[\1 0 0 0 0 1 0 1 0 1 0 0 0 0 1 0 1 0 Rearrange (>:i.3 4) in a shape (4 3 3) noun according to that template. Like T ((-@#@])[\"1 ,@[ #^:_1"1|:@])>:i.3 4 1 0 0 0 0 5 0 9 0 2 0 0 0 0 6 0 10 0 3 0 0 0 0 7 0 11 0 4 0 0 0 0 8 0 12 0 (2 _2 {."0"1 |: arr1,:arr2) -: (1 0,: 0 1) ((-@#@])[\"1 ,@[ #^:_1"1|:@])>:i.2 3 1 R.E. Boss -----Original Message----- From: Programming <[email protected]> On Behalf Of R.E. Boss Sent: zaterdag 8 augustus 2020 11:02 To: [email protected] Subject: Re: [Jprogramming] Constructing arrays by filling "templates" 2 _2 {."0"1 |: arr1,:arr2 R.E. Boss -----Original Message----- From: Programming <[email protected]> On Behalf Of xash@?.land Sent: zaterdag 8 augustus 2020 10:31 To: [email protected] Subject: Re: [Jprogramming] Constructing arrays by filling "templates" (0 0;1 1)}&(2 2$0)"1 (arr1 ,. arr2) On Sat, 08 Aug 2020 10:13:08 +0200 Thomas Bulka <[email protected]> wrote: > Hello everyone, > > I'm stuck with a problem, which (I think) should be really easy to > solve in J, but I somehow am not able to do it. This is what I want to do: > > Let's assume I have two arrays: > > arr1 =: 1 2 3 > arr2 =: 4 5 6 > > Now I do imagine some kind of "template" for a matrix which looks like > this: > > X 0 > 0 Y > > What I want to do now is to construct a rank-3 array (shape 3 2 2), in > which in each consecutive plane X has been replaced by one element of > arr1 and Y has been replaced with one element of arr2. The final array > should therefore be: > > finalarr =: 3 2 2 $ 1 0 0 4 2 0 0 5 3 0 0 6 > > I'm looking for a sentence/function, that constructs an array of shape > n > 2 2 (in the example given above) where n equals # arr1 (we can assume > that (# arr1) = # arr2). As I said - I've got the feeling that this > should be not too hard to do in J, but somehow I'm stuck. > > Thank you very much for your help! > > Regards, > > Thomas > > ---------------------------------------------------------------------- > 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 ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
