hermann on Mon, 18 Nov 2024 16:48:45 +0100 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Re: Is there a function for sum of square matrix antidiagonal like "trace()" for main diagonal? |
On 2024-11-18 15:57, Bill Allombert wrote:
or atr(~M)=my(j=#M+1);sum(i=1,#M,j--;M[i,j]); atr2(~M)=sum(i=1,#M,M[i,#M+1-i]); for(i=1,100000,atr(~M)) for(i=1,100000,atr2(~M))
Thanks Bill, that atr2 is fastest. On 2024-11-18 15:34, hermann@stamm-wilbrandt.de wrote:
M~ is transpose matrix M. Is there some other operator in GP such that atr(M) == trace(op(M)) ?
trace(op(~M)) is slower than atr2, but I finally got it: op(~M)=Mat([M[-i,]~|i<-[-#M..-1]]); Regards, Hermann.