Discussion: new operators for numerical computation

Gregory Lielens gregory.lielens at fft.be
Thu Jul 20 14:17:17 EDT 2000


Paul Magwene wrote:
> 
> Tim Hochberg wrote:
> >
> > Gregory Lielens <gregory.lielens at fft.be> writes:
> >
> > > Tim Hochberg wrote:
> > [...]
> > > I like the parethese a lot! except for ° which is probably out of
> > > question,
> > > this is the prettier way to do it, but (alwas a but :-( )
> > >
> > > - the solve operator indeed...The only thing i can come with is the ugly
> > > (%)
> > >   or the pretty but out-of-question (\)
> >
> > My favorite right now is |. So one would have:
> >
> > A[*]B    # matouter
> > A(*)B    # matinner
> > A(/)B    # matdiv
> > A(|)B    # matsolve
> > A(^)B    # matpower
> >
> > Alternatively, one could use:
> >
> > A(*)B   # matouter
> > A(.)B   # matinner (AKA dot, get it?)
> >
> > That would cut down on the available symbols, but might make parsing
> > easier? It might also be easier to distinguish between the two
> > products.
> >
> > I've left out other potential outer operators (outer sum, etc) and
> > alternate inner products (Lie, Kroneker, ?) pending finding a
> > constituency for them.
> 
> Kronecker products get used enough (at least in statistics) that I'd
> hope we'd include 'em (we're already on our way down the slippery slope,
> so I may as well lobby for operators *I* want ;-).
> 
> How about:
> 
> A{*}B   # matkron
> 
> (Paralleling A[*]B for matouter, and A(*)B for matinner)

I think thay may be a little too many products here( - I never though I
would say that :-)), am i wrong?
I would let the inner (*) and element product * be the main one (they
are the more used, I think ... at least
tey were the only one i was aware of (except vector/cross product for
vectors) 2 hours ago!)
The other ones could be functions, or mapped to a third unallowed
product-like sign, [*] for example, depending
on your particular field...A general inner/outer product specifing
indices of contraction,and new dummy indices, could probably be used to
defined quite easily all these particular products...

here is my attempt for matouter a[*]b as an example, using my previous
notation and a RemoveAxis which would be the pendant 
of NumPy NewAxis and will change a rank n tensor into a rank n-1 tensor
with the same number of elements (a generalisation of matlab a(:) which
transform a matrix in a column vector) (if this looks completely
ridiculous to you - it probably is, i am a beginner both in Python and
NumPy, so do not hesitate to correct my stupid errors!)

def __specialproduct__(self,b):
  rank4tensor = self.i(1,2) (*) b.i(3,4)
  return(rank4tensor[RemoveAxis,RemoveAxis,:,:])

What do you think?

Greg.



More information about the Python-list mailing list