Don, my function doesn't apply to a 3D array. However, shouldn't the
diagonal of  B  be  0 13 26 ? 

   ]B=: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)|:B
0 12 24
1 13 25
2 14 26

Linda
-

----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Linda Alvord
Sent: Wednesday, March 06, 2013 2:04 AM
To: [email protected]
Subject: Re: [Jprogramming] extacting the main diagonal of a square matrix

    ]A=:?(2#>:?8)$8
7 7 0 6 6 5 5
5 3 2 4 0 1 0
2 2 7 2 6 3 2
2 4 3 5 7 3 4
6 0 1 4 6 2 0
2 0 4 1 4 1 2
7 3 5 4 3 7 3
   
   f=: 13 :'0{"1(|i.#y)|."0 1 y'

   f A
7 3 7 5 6 1 3
    
   f
0 {"1 ] |."0 1~ [: | [: i. #
   
Linda

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Tom Arneson
Sent: Tuesday, March 05, 2013 10:12 PM
To: [email protected]
Subject: [Jprogramming] extacting the main diagonal of a square matrix

I want to create a list containing the main diagonal elements of a square
matrix. Any suggestions?

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