a=: i.3 4 5 6

   (0 0 0 0;1 1 1 1;2 2 2 2){a
0 157 314
   (<0 1 2 3)|:a
0 157 314
   (<@i.@#@$ |: ]) a
0 157 314

   trace=: [: +/ <@i.@#@$ |: ]
   trace a
471


On Fri, Sep 4, 2020 at 7:37 PM pietdion <[email protected]> wrote:

> The trace of matrix (2 dimensional array) is implemented with
>
> tr=: +/@:((<0 1)&|:)
>
> (BTW:   The "(<0 1)&|:"   always mystifies me.)
>
> Can someone point me to an efficient and terse verb that generalises the
> trace to arbitrary dimensions?
> A verb that works on 1  and higher than 2 dimensional arrays.
>
> ----------------------------------------------------------------------
> 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