I'm a beginner. So bear with me please if my questions look dumb. I'm trying to define a function which takes a matrix as input and returns the sum of all entries along a specified sub or super anti-diagonal.
Here is a piece of code that I found at stackexchange, which returns the k-th anti-diagonal.
k
antidiag[m_, k_] := Diagonal[m[[k ;; -1, k ;; -1]][[-1 ;; 1 ;; -1, 1 ;; -1 ;; 1]]]
Here are my questions:
;;
Span
-1
k;;-1
-1 ;; 1 ;; -1
m
m[[...]]
m[[...]][[...]]
Thanks a lot!!
negative indices count from the end: -1 the last, -2 the penultimate, et cetera so:
{4,5,6,7,8,9}[[-1;;1;;-1]]
does reverse: "pick from end to beginning in steps of -1"
Aha! Thanks, I see it now! Thanks very much!