
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

Hi Donald On Thu, Oct 04, 2007 at 01:48:18AM +0000, Donald Fredkin wrote:
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()
Thanks for the report. This is already fixed in the latest version: In [11]: A.trace(0,1,2) Out[11]: array([ 3, 11]) In [12]: N.trace(A,0,1,2) Out[12]: array([ 3, 11]) In [13]: N.__version__ Out[13]: '1.0.4.dev4149' Regards Stéfan
participants (2)
-
Donald Fredkin
-
Stefan van der Walt