Harald Hanche-Olsen | 29 Jan 2000 03:37
Picon
Picon
Favicon
Gravatar

A proposal for dot (or inner)

I am having some problems relating to the current function dot
(identical to matrixmultiply, though I haven't seen the equivalence in
any documentation).  Here is what the docs say:

  dot(a,b) 

  Will return the dot product of a and b. This is equivalent to matrix
  multiply for 2d arrays (without the transpose).  Somebody who does
  more linear algebra really needs to do this function right some day!

Or the builtin doc string:

  >>> print Numeric.dot.__doc__
  dot(a,b) returns matrix-multiplication between a and b.  The product-sum
      is over the last dimension of a and the second-to-last dimension of b.

First, this is misleading.  It seems to me to indicate that b must
have rank at least 2, which experiments indicate is not necessary.
Instead, the rule appears to be to use the only axis of b if b has
rank 1, and otherwise to use the second-to-last one.

Frankly, I think this convention is ill motivated, hard to remember,
and even harder to justify.  As a mathematician, I can see only one
reasonable default choice: One should sum over the last index of a,
and the first index of b.  Using the Einstein summation convention
[*], that would mean that

   dot(a,b)[j,k,...,m,n,...] = a[j,k,...,i] * b[i,m,n,...]

[*] that is, summing over repeated indices -- i in this example
(Continue reading)


Gmane