[Numpy-discussion] dot product not behaving as expected

Robert Kern robert.kern at gmail.com
Mon Oct 8 12:40:27 EDT 2007


Robin wrote:
> Hi,
> 
> I have a problem using numpy.dot, see below:
> 
> In [151]: m=5
> 
> In [152]: n=5
> 
> In [153]: x=(m*ones((1,5)))**arange(0,n)
> 
> In [154]: y=test.order_length[::-1]
> 
> In [155]: x
> Out[155]: array([[   1.,    5.,   25.,  125.,  625.]])
> 
> In [156]: y
> Out[156]:
> array([[ 1024.],
>        [ 1280.],
>        [  640.],
>        [  160.],
>        [   20.]])
> 
> In [157]: numpy.dot(x,y)
> Out[157]: array([[ 640000.]])
> 
> In [158]: sum(x* y.T)
> Out[158]: 55924.0
> 
> Am I missing something?

In [1]: from numpy import *

In [2]: x = array([[   1.,    5.,   25.,  125.,  625.]])

In [3]: y = array([[ 1024.],
   ...:        [ 1280.],
   ...:        [  640.],
   ...:        [  160.],
   ...:        [   20.]])

In [4]: dot(x, y)
Out[4]: array([[ 55924.]])

In [5]: sum(x * y.T)
Out[5]: 55924.0


It works for me with a recent SVN numpy on OS X. What version of numpy are you
using? What platform are you on? Did you build with ATLAS or other optimized
linear algebra library?

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco



More information about the NumPy-Discussion mailing list