[Jprogramming] extacting the main diagonal of a square matrix

Don Guinn donguinn at gmail.com
Wed Mar 6 13:18:51 UTC 2013


   (<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 <lindaalvord at verizon.net>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
> -
>
>


More information about the Programming mailing list