bd=. >@:(([ , ] ,"1~ 0 [EMAIL PROTECTED] [)&.>/) NB. Based on Andrew
Nikitin's dyad
diag=: ;@({."1&.>~ +/\@:([EMAIL PROTECTED]@$@>))
This seems to work fine,
A=. i.@,~&.> i.4
(bd -: diag)A
1
However...
B=. <"_1 @: i. 5 2 3
(bd -: diag)B
0
bd B
0 1 2 0 0 0 0 0 0 0 0 0 0 0 0
3 4 5 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 6 7 8 0 0 0 0 0 0 0 0 0
0 0 0 9 10 11 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 12 13 14 0 0 0 0 0 0
0 0 0 0 0 0 15 16 17 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 18 19 20 0 0 0
0 0 0 0 0 0 0 0 0 21 22 23 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 24 25 26
0 0 0 0 0 0 0 0 0 0 0 0 27 28 29
diag B
1 2 0 0 0 0 0 0 0 0
4 5 0 0 0 0 0 0 0 0
0 6 7 8 0 0 0 0 0 0
0 9 10 11 0 0 0 0 0 0
0 0 0 12 13 14 0 0 0 0
0 0 0 15 16 17 0 0 0 0
0 0 0 0 0 18 19 20 0 0
0 0 0 0 0 21 22 23 0 0
0 0 0 0 0 0 0 24 25 26
0 0 0 0 0 0 0 27 28 29
> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:programming-
> [EMAIL PROTECTED] On Behalf Of Miller, Raul D
> Sent: Friday, June 23, 2006 3:55 PM
> To: Programming forum
> Subject: RE: [Jprogramming] Block-Diagonal Matrices
>
> Although this is not precisely what was asked for, here's a mechanism to
> turn a boxed list of matrices into a diagonal:
>
> diag=: ;@({."1&.>~ +/\@:([EMAIL PROTECTED]@$@>))
>
> For example:
> diag i.@,~&.> i.4
> 0 0 0 0 0 0
> 0 0 1 0 0 0
> 0 2 3 0 0 0
> 0 0 0 0 1 2
> 0 0 0 3 4 5
> 0 0 0 6 7 8
>
> That said, diag M1;M2 would satisfy the original request (unless M1 or
> M2 are sparse -- sparse arrays do not fit in boxes in J6).
>
> --
> Raul
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm