[PYTHON MATRIX-SIG] default axes

Janne Sinkkonen janne@avocado.pc.helsinki.fi
15 Aug 1996 16:18:25 +0300

Konrad Hinsen      <hinsen@physik.rwth-aachen.de> writes:

> Actually, dot() is the only function about which I am not sure.
> There are several options that make sense:
> 1) Axis -1 for both arguments. Good for vectors and lists of vectors.

2D-matrices are lists of vectors. The interpretation just depends. :)

> 2) Axis -1 for the first and -2 for the second. Good for matrices
>    and lists of matrices.

This would require the second argument to be two-dimensional. I would
prefer a dot() which would give a scalar when applied to two vectors.
This holds for 1) and 3).

> 3) Axis -1 for the first and 0 for the second. Good for higher-rank
>    tensors.
> My personal favourite is 3), but I can't give any relly good argument.

I prefer 3) now.

3) would be nice for 2D matrices, because then 0 would be the
same as -2.

dot() refers to the mathematical concept of dot product or inner
product, and I guess 3) would fulfill some clean formal definition
provided both arguments are real objects and not lists of objects.

If add.reduce() would operate on -1, then a dot like proposed in 1)
would be equivalent to add.reduce(a*b) which is not too difficult to
write, thus that kind of dot() would be more redundant than 3). On the
other hand, Konrad had a good argument against reducing -1 (python's
standard reduce reduces axis 0), so I'm not sure anymore about that.

How about two functions? dot() would be like 3), and then there could
be 'vdot()' (vector dot) like 1)? vdot() would eliminate the commonly
needed add.reduce(a,b,-1), thus add.reduce() could reduce over 0 by

> But evidently dot() needs two optional axis arguments to cover all cases.

I agree.


MATRIX-SIG  - SIG on Matrix Math for Python

send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org