[Numpy-discussion] Possible bug in numpy.trace()
Donald Fredkin
drfredkin@ucsd....
Wed Oct 3 20:48:18 CDT 2007
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
More information about the Numpy-discussion
mailing list