3 Oct
2007
3 Oct
'07
8:48 p.m.
It appears that something peculiar is going on with the numpy function trace(). The docs say that trace(A,...) is identical to A.trace(...). Here is a test: A = arange(8).reshape((2,2,2)) A.trace(0,1,2) #[Out]# array([ 3, 11]) # which is correct trace(A,0,1,2) #[Out]# array([6, 8]) #which is wrong #Since trace() is computed by summing the result of diagonal() A.diagonal(0,1,2) #[Out]# array([[0, 3], #[Out]# [4, 7]]) #which is correct diagonal(A,0,1,2) #[Out]# array([[0, 3], #[Out]# [4, 7]]) #which is the same correct result A.trace(0,0,1) #[Out]# array([6, 8]) #this is the erroneous answer we found earlier for trace(A,0,1,2) -- Donald R. Fredkin drfredkin@ucsd.edu