[Numpy-discussion] [help needed] associativity and precedence of '@'
Alexander Belopolsky
ndarray at mac.com
Sat Mar 15 15:58:51 EDT 2014
On Sat, Mar 15, 2014 at 3:29 PM, Nathaniel Smith <njs at pobox.com> wrote:
> > It would be nice if u at v@None, or some such, would evaluate as a dyad.
> Or else we will still need the concept of row and column 1-D matrices. I
> still think v.T should set a flag so that one can distinguish u at v.T(dyad) from u.T at v(inner product), where 1-D arrays are normally treated as column vectors.
>
> This sounds important but I have no idea what any of it means :-) (What's
> a dyadic matrix?) Can you elaborate?
>
I assume dyadic means 2d.
This discussion gave me an idea that is only tangentially relevant to the
discussion at hand. It looks like numpy operators commonly need to make a
choice whether to treat an Nd array as a unit (atom) or as a list to
broadcast itself over.
APL-derived languages solve this problem by using operator modifiers.
Applied to our case, given a dot-product operator @, each[@] operator
works on 2d arrays by "dotting" them pair-wise and returning a 1d array.
Similarly, eachleft[@] would operate on 2d, 1d operands by broadcasting
itself over the left operand (incidentally reproducing the mat @ vec
behavior) and eachright[@] would treat its left operand atomically and
broadcast over the right operand.
My idea is inspired by Guido's "use facade" suggestion. We can define
ndarray.each(axes=(0,)) method that would return a light-weigh proxy object
so that
a each[@] b is spelled a.each() @ b.each()
a eachleft[@] b is spelled a.each() @ b
a eachright[@] b is spelled a @ b.each()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20140315/7dc9f04e/attachment.html>
More information about the NumPy-Discussion
mailing list