[Numpy-discussion] adding a .M attribute to the array.

John J. Lee jjl at pobox.com
Fri Mar 8 13:42:07 CST 2002


On Thu, 7 Mar 2002, Konrad Hinsen wrote:

> "eric" <eric at enthought.com> writes:
>
> > Matrix.Matrix objects. This attribute approach will work, but I
> > wonder if trying the "adding an operator to Python" approach one
> > more time would be worth while. At Python10 developer's day, Guido
[...]
> If you want to go the "operator way", the goal should rather be
> something like APL, with composite operators. Matrix multiplication
[...]

How about general operator - function equivalence, as explained here by
Alex Martelli?  The change is large in one sense, but it is conceptually
very simple:

http://groups.google.com/groups?q=operator+Martelli+Haskell+group:comp.lang.python&hl=en&selm=8t4dl301a4%40news2.newsguy.com&rnum=1

>   2 div 3
> or
>   div(2,3)
> or
>   2 `div 3
> [Haskell-ishly syntax-sugar note: Haskell lets you
> use any 2-operand function as an infix operator by
> just enclosing its name in ``; in Py3K, I think a
> single leading ` would suffice -- far nicer than the
> silly current use of ` for the rare need of repr --
> and we might also, with pleasing symmetry, let any
> operator be used as a normal function a la
>     `+(a,b)
> i.e., the ` marker could lexically switch functions
> to operators and operators to functions, without
> needing to 'import operator' and recall what the
> operator-name for a given operator IS...!-).  The
> priority and associativity of these infinitely
> many "new operators" could be fixed ones...].

Since GvR seems to have given up the idea of 'Py3K' in favour of gradual
changes, perhaps this is a real possibility?

Travis'

r = a.M * b.M

would then be written as

M = Numeric.matrixmultiply
r = a `M b

(Konrad also complains about Perl's nasty syntax.  This is frequently
complained about, but do you really think the syntax is the problem --
surely it's Perl's horribly complicated semantics that is the real issue?
The syntax is just inconvenient, in comparison at least.  Sorry, a bit
OT...)


John





More information about the Numpy-discussion mailing list