[SciPy-user] Strange behaviour of dot function

"Johannes Löhnert" a.u.r.e.l.i.a.n at gmx.net
Mon Jan 30 11:50:48 EST 2006


Hi,

I just found out that the dot function which multiplies matrices gives
strange results for a 3-dimensional array. Consider the following example:

-----------------
from Numeric import *
#from numpy import *

a=(arange(-1,3)[:, NewAxis, NewAxis]
   +arange(1,3)[NewAxis, :, NewAxis]
   +arange(3,6)[NewAxis, NewAxis, :])
print a

n=a.shape[1]

print 'sum:\n',  sum(a, axis=1)
print 'dot1:\n', dot(ones(n), a)
print 'dot2:\n', dot(swapaxes(a,1,2), ones(n))
----------------

My expectation would be that all three of the last lines give the same
result. However, only 'sum' and 'dot2' are equal. (using Numeric 23.8)

As you probably guessed I also tried it with a recent numpy version
(numpy.__version__ = 0.9.5.1983). In this case, both dot1 and dot2 give the
wrong result.

Question: Is this behaviour intended? If yes, how do you get to the 'wrong'
result?


Johannes Loehnert

-- 
Telefonieren Sie schon oder sparen Sie noch?
NEU: GMX Phone_Flat http://www.gmx.net/de/go/telefonie




More information about the SciPy-User mailing list