[Numpy-discussion] Two questions about PEP 465 dot product

Nathaniel Smith njs at pobox.com
Fri May 22 14:23:02 EDT 2015

```On May 22, 2015 11:00 AM, "Alexander Belopolsky" <ndarray at mac.com> wrote:
>
>
> On Thu, May 21, 2015 at 9:37 PM, Nathaniel Smith <njs at pobox.com> wrote:
> >
> > .. there's been some discussion of the possibility of
>
> > vector-matrix, matrix-vector multiplication, which wouldn't do the
> > magic vector promotion that dot and @ do.
>
>
> This would be nice.  What I would like to see is some consistency between
multi-matrix
> support in linalg methods and dot.
>
> For example, when A is a matrix and b is a vector and
>
> a = linalg.solve(A, b)
>
> then
>
> dot(A, a) returns b, but if either or both A and b are stacks, this
invariant does not hold.  I would like
> to see a function (say xdot) that I can use instead of dot and have
xdot(A, a) return b whenever a = linalg.solve(A, b).

I believe this equivalence holds if xdot(x, y) = x @ y, because solve()
does follow the pep 465 semantics for shape handling. Or at least, it's
intended to. Of course we will also expose pep 465 matmul semantics under
some name that doesn't require the new syntax (probably not "xdot" though
;-)).

> Similarly, if w,v =  linalg.eig(A), then dot(A,v) returns w * v, but only
if A is 2d.

Again A @ v I believe does the right thing, though I'm not positive -- you
might need a swapaxes or matvec or something. Let us know if you work it
out :-).

Note that it still won't be equivalent to w * v because w * v doesn't
broadcast the way you want :-). You need w[..., np.newaxis, :] * v, I think.

-n

>
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20150522/949c18ba/attachment.html>
```