i.3 3 3
 0  1  2
 3  4  5
 6  7  8

 9 10 11
12 13 14
15 16 17

18 19 20
21 22 23
24 25 26
   (<0 1 2)|:i.3 3 3
0 13 26
   (<0 1)|:i.3 3 3
0 12 24
1 13 25
2 14 26

2012/1/7 "Papp Erik Tamás" <papp.e...@ybl.szie.hu>

> Hi,
>
> Some example of getting the main diagonal of square matrices:
>
>   ]A=:2 2$1 2 3 4
> 1 2
> 3 4
>
>   (<0 1)|:A NB. The main diagonal of a square matrix A
> 1 4
>
>   ]B=:3 3$1 2 3 4 5 6
> 1 2 3
> 4 5 6
> 1 2 3
>
>   (<0 1)|:B NB. The main diagonal of a square matrix B
> 1 5 3
>
>   ]N=:4 4$i. 16
>  0  1  2  3
>  4  5  6  7
>  8  9 10 11
> 12 13 14 15
>
>   (<0 1)|:N NB. The main diagonal of a square matrix N
> 0 5 10 15
>
> Regards,
>
> Erik
>  ----- Eredeti levél (Original Message) -----
> Feladó: Alex Giannakopoulos <aeg...@blueyonder.co.uk>
> Dátum: Péntek, Január 6, 2012 9:48 du
> Tárgy: [Jprogramming] Getting the diagonal of a square matrix
> Címzett: Programming forum <programming@jsoftware.com>
>
> > Hi
> >
> > Is there a better (more efficient or whatever) way of getting
> > the diagonal
> > of a matrix than the simple multiplication I use below?
> >
> > Say,
> >
> >    randmat=. [: ? 0 $~,~
> >    idmat =. [:=i.
> >    randiag =. randmat * idmat
> >
> > Many Thanks
> > -----------------------------------------------------------------
> > -----
> > 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

Reply via email to