I like:

   (<0 1 2 3)|:B=:i.4 4 4 4
0 85 170 255

Linda

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

   (<0 1 2)|:B
0 13 26

Or -
   (<i.#$B)|:B=.i. 3 3 3 3
0 40 80

On Wed, Mar 6, 2013 at 12:35 AM, Linda Alvord
<[email protected]>wrote:

> 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
> -
>
>
----------------------------------------------------------------------
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