[Numpy-discussion] Some questions about dot()

Bill Baxter wbaxter at gmail.com
Mon May 1 04:49:15 EDT 2006


Hi Gary,

On 5/1/06, Gary Ruben <gruben at bigpond.net.au> wrote:
>
> Hi Bill,
>
> It looks to me like dot() is doing the right thing. Can you post an
> example of why you think it's wrong?


It /is/ behaving as documented, if that's what you mean.  But the question
is why it acts that way.
Simple example:
>>> numpy.__version__, os.name
('0.9.5', 'nt')
>>> a = numpy.asmatrix([1.,2.,3.]).T
>>> a
matrix([[ 1.],
       [ 2.],
       [ 3.]])
>>> numpy.dot(a,a)
Traceback (most recent call last):
  File "<input>", line 1, in ?
ValueError: matrices are not aligned
>>> numpy.dot(a.T,a)
matrix([[ 14.]])

Everywhere I've ever encountered a dot product before it's been equivalent
to the transpose of A times B.  So a 'dot()' function that acts exactly like
a matrix multiply is a bit surprising to me.

After poking around some more I found numpy.vdot() which is apparently
supposed to do the standard "vector" dot product.  However, all I get from
that is:
>>> a
matrix([[ 1.],
       [ 2.],
       [ 3.]])
>>> numpy.vdot(a,a)
Traceback (most recent call last):
  File "<input>", line 1, in ?
ValueError: vectors have different lengths
>>>

Also in the same numpy.core._dotblas module as dot and vdot, there's an
'inner', which claims to be an inner product, but seems to only work when
called with both arguments transposed as follows:
>>> numpy.inner(a.T, a.T)
array([[ 14.]])


2a) re. the docstring - this looks like a 'bug'; presumably an old
> docstring not correctly updated.


I think maybe 'matrixproduct' is supposed to be 'matrixmultiply' which /is/
a synonym for dot.


2b) "generic numpy equivalent" - agree that this isn't very enlightening.





--
William V. Baxter III
OLM Digital
Kono Dens Building Rm 302
1-8-8 Wakabayashi Setagaya-ku
Tokyo, Japan  154-0023
+81 (3) 3422-3380
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20060501/c2781557/attachment.html>


More information about the NumPy-Discussion mailing list