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
Johannes Löhnert wrote:
Hi,
I just found out that the dot function which multiplies matrices gives strange results for a 3-dimensional array. Consider the following example:
You just found two bugs in numpy.dot one of which is also there in Numeric. I just committed a fix to both bugs by using the ever-useful N-d array iterator (it sure makes it easier to write algorithms for strided arrays...). All three of your tests now produce the same answer. Thank you for finding this problem. -Travis
participants (2)
-
"Johannes Löhnert" -
Travis Oliphant