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? Thanks, Robin
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
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?
I am on Ubuntu 7.04, gcc 4.1.2 In [181]: numpy.__version__ Out[181]: '1.0.4.dev4155' Built with ATLAS 3.7.37, Lapack 3.1.1 It also occurs for me on Windows XP SP2 with 1.0.4dev4154 built with cygwin gcc 3.4.4 and atlas 3.7.37 and lapack 3.1.1. Actually I found that for me it also doesn't occur if I type them in like that. The problem comes when y is reverse with the [::1] index. Is this the correct way to reverse a vector? Anyway try this: In [36]: x=array([[1.,5.,25.,125.,625.]]) In [37]: y=array([[20.],[160.],[640.],[1280.],[1024.]]) In [38]: y Out[38]: array([[ 20.], [ 160.], [ 640.], [ 1280.], [ 1024.]]) In [39]: y2=y[::1] In [40]: y2 Out[40]: array([[ 1024.], [ 1280.], [ 640.], [ 160.], [ 20.]]) In [41]: dot(x,y) Out[41]: array([[ 816820.]]) In [42]: dot(x,y2) Out[42]: array([[ 640000.]]) Thanks, Robin
Robin wrote:
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?
I am on Ubuntu 7.04, gcc 4.1.2
In [181]: numpy.__version__ Out[181]: '1.0.4.dev4155'
Built with ATLAS 3.7.37, Lapack 3.1.1
It also occurs for me on Windows XP SP2 with 1.0.4dev4154 built with cygwin gcc 3.4.4 and atlas 3.7.37 and lapack 3.1.1.
Actually I found that for me it also doesn't occur if I type them in like that. The problem comes when y is reverse with the [::1] index. Is this the correct way to reverse a vector?
Aha. Yes, that is the correct way to do it. However, it appears that there is a bug in how dot() is interpreting the noncontiguous array. In the meantime, you can make a contiguous array with array(y2).  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
On 10/8/07, Robert Kern <robert.kern@gmail.com> wrote:
Aha. Yes, that is the correct way to do it. However, it appears that there is a bug in how dot() is interpreting the noncontiguous array. In the meantime, you can make a contiguous array with array(y2).
Thanks very much for the prompt help! Should I open a ticket for this issue? Robin
Robin wrote:
On 10/8/07, *Robert Kern* <robert.kern@gmail.com <mailto:robert.kern@gmail.com>> wrote:
Aha. Yes, that is the correct way to do it. However, it appears that there is a bug in how dot() is interpreting the noncontiguous array. In the meantime, you can make a contiguous array with array(y2).
Thanks very much for the prompt help!
Should I open a ticket for this issue?
Please!  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
participants (2)

Robert Kern

Robin