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.
antidiag[m_, k_] := Diagonal[m[[k ;; -1, k ;; -1]][[-1 ;; 1 ;; -1, 1 ;; -1 ;; 1]]]
Here are my questions:
- I understand the general use of
;;forSpan. But I don’t understand the many-1here. What dok;;-1and-1 ;; 1 ;; -1mean, respectively? - For a matrix
m, I understand the indexing usingm[[...]]. But what doesm[[...]][[...]]mean? Can anyone give me a pointer for this syntax?
Thanks a lot!!
[1]: http://mathematica.stackexchange.com/questions/23240/is-there-a-built-in-function-to-obtain-the-back-diagonal-of-a-matrix