[Numpy-discussion] Simple multi-arg wrapper for dot()
Sat Mar 24 14:03:11 CDT 2007
On 3/24/07, Anne Archibald <firstname.lastname@example.org> wrote:
> On 24/03/07, Bill Baxter <email@example.com> wrote:
> > Nice, but how does that fare on things like mdot(a,(b,c),d) ? I'm
> > pretty sure it doesn't handle it.
> > I think an mdot that can only multiply things left to right comes up
> > short compared to an infix operator that can easily use parentheses to
> > control order.
> Well, since exact dotting is associative, the parenthesization doesn't
> matter there; if you're worried about roundoff or efficiency, you're
> going to have to be more explicit.
Yes performance was the thing I was thinking about. You often know a
little something about the sizes of your inputs that can help make
things more efficient. Like
BigMatrix1 * BigMatrix2 * LittleVector
Is much faster to calculate as
BigMatrix1 * (BigMatrix2 * LittleVector)
(BigMatrix1 * BigMatrix2) * LittleVector
> Unfortunately your approach requires tuples to be treated differently from arrays.
Yeh, that was a conscious decision (which I noted in the docstring).
You are right that it is different from what Numpy normally does,
which is one reason I didn't say "lets replace dot with this
> Most functions
> in numpy will happily treat a tuple of length n, a list of length n,
> and an array of length n the same way.
Yep, it's nice in general. But in practice I very rarely do math on
tuples. The only thing I can think of is I used to do prod(arr.shape)
before I realized that arr.size give the same thing. I'm positive
I've never used dot on tuples.
> You could do this, and for your
> own code maybe it's worth it, but I think it would be confusing in the
Could be. Doesn't seem so confusing to me as long as it's documented
clearly in the docstring, but YMMV.
More information about the Numpy-discussion