[Numpy-discussion] inconsistent dot() behaviour

Travis Oliphant oliphant at ee.byu.edu
Mon Mar 13 14:10:09 EST 2006


Chris Fonnesbeck wrote:

>I notice that the dot() function does not behave consistently across
>all sizes of arrays:
>
>In [7]: dot(array([1.0]), array([-0.27163628]))
>Out[7]: array([-0.27163628])
>
>In [8]: dot(array([1.0,1.0]), array([-0.27163628,1.0]))
>Out[8]: 0.72836371999999994
>
>Why should a 1x1 dot product produce an array, while a 2x2 (or
>greater) product produces a scalar?
>  
>
It's an error. 

Basically, you can check to make sure the optimized dot function is 
doing what it should by running

from numpy.core.multiarray import dot as olddot

and checking the output of olddot against the optimized dot output.

They should be the same or it's a problem.  

We should write a test that loops through problems of dimensions 0, 1, 2 
and computes the result both ways checking the output for equivalency.   
Some of this is done, but obviously another case was missed.


-Travis





More information about the NumPy-Discussion mailing list