Every so often the idea of new operators comes up because of the need to do both "matrix-multiplication" and element-by-element multiplication. I think this is one area where the current Python approach is not as nice because we have a limited set of operators to work with. One thing I wonder is if we are being vocal enough with the Python 3000 crowd to try and get additional operators into the language itself. What if we could get a few new operators into the language to help us. If we don't ask for it, it certainly won't happen. My experience is that the difficulty of using the '*' operator for both matrix multiplication and element-by-element multiplication depending on the class of the object is not especially robust. It makes it harder to write generic code, and we still haven't gotten everything completely right. It is somewhat workable as it stands, but I think it would be nicer if we could have some "meta" operator that allowed an alternative definition of major operators. Something like @* for example (just picking a character that is already used for decorators). I wonder if we should propose such a thing for Python 3000. -Travis
Hi,
I followed the discussion on the scipy ML, and I would advocate it as well.
I miss the dichotomy that is present in Matlab, and to have a similar degree
of freedom, it would be good to have it in the upcoming major release of
Python.
Matthieu
2007/3/24, Travis Oliphant
Every so often the idea of new operators comes up because of the need to do both "matrix-multiplication" and element-by-element multiplication.
I think this is one area where the current Python approach is not as nice because we have a limited set of operators to work with.
One thing I wonder is if we are being vocal enough with the Python 3000 crowd to try and get additional operators into the language itself.
What if we could get a few new operators into the language to help us. If we don't ask for it, it certainly won't happen. My experience is that the difficulty of using the '*' operator for both matrix multiplication and element-by-element multiplication depending on the class of the object is not especially robust. It makes it harder to write generic code, and we still haven't gotten everything completely right.
It is somewhat workable as it stands, but I think it would be nicer if we could have some "meta" operator that allowed an alternative definition of major operators. Something like @* for example (just picking a character that is already used for decorators).
I wonder if we should propose such a thing for Python 3000.
-Travis
_______________________________________________ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
On 3/24/07, Travis Oliphant
Every so often the idea of new operators comes up because of the need to do both "matrix-multiplication" and element-by-element multiplication.
I think this is one area where the current Python approach is not as nice because we have a limited set of operators to work with.
One thing I wonder is if we are being vocal enough with the Python 3000 crowd to try and get additional operators into the language itself.
What if we could get a few new operators into the language to help us. If we don't ask for it, it certainly won't happen. My experience is that the difficulty of using the '*' operator for both matrix multiplication and element-by-element multiplication depending on the class of the object is not especially robust. It makes it harder to write generic code, and we still haven't gotten everything completely right.
It is somewhat workable as it stands, but I think it would be nicer if we could have some "meta" operator that allowed an alternative definition of major operators. Something like @* for example (just picking a character that is already used for decorators).
Yes indeed, this is an old complaint. Just having an infix operator would be an improvement: A dot B dot C Not that I am suggesting dot in this regard ;) In particular, it wouldn't parse without spaces. What about division? Matlab has both / and \ for left and right matrix division and something like that could call solve instead of inverse, leading to some efficiencies. We also have both dot and tensordot, which raises the problem of interpretation when ndim > 2. Chuck
On 3/24/07, Charles R Harris
On 3/24/07, Travis Oliphant
wrote: Every so often the idea of new operators comes up because of the need to do both "matrix-multiplication" and element-by-element multiplication.
I think this is one area where the current Python approach is not as nice because we have a limited set of operators to work with.
One thing I wonder is if we are being vocal enough with the Python 3000 crowd to try and get additional operators into the language itself.
What if we could get a few new operators into the language to help us. If we don't ask for it, it certainly won't happen. My experience is that the difficulty of using the '*' operator for both matrix multiplication and element-by-element multiplication depending on the class of the object is not especially robust. It makes it harder to write generic code, and we still haven't gotten everything completely right.
It is somewhat workable as it stands, but I think it would be nicer if we could have some "meta" operator that allowed an alternative definition of major operators. Something like @* for example (just picking a character that is already used for decorators).
Yes indeed, this is an old complaint. Just having an infix operator would be an improvement:
A dot B dot C
Not that I am suggesting dot in this regard ;) In particular, it wouldn't parse without spaces. What about division? Matlab has both / and \ for left and right matrix division and something like that could call solve instead of inverse, leading to some efficiencies. We also have both dot and tensordot, which raises the problem of interpretation when ndim > 2.
Chuck
I understand the convenience of more infix operators. And I sometimes think one should just be able to define new ones at will .... On the other hand, I'm now playing the devil's advocate: A "math specific" language like Matlab has obviously an overwhelming need for a second set of matrix/array operators. However, a language -- as broadly used as -- Python might be just better off having a simple, concise and limited set of infix operators. I assume that this is the official argument. I got especially "worried" when being remember of the "\" right-to-left division operator. (As I said, it very useful to have in Matlab, and I wish sometimes we could add things like this). It is just important to keep the "con" - argument clearly in mind. I hope this helps the discussion. - Sebastian Haase
On 24/03/07, Charles R Harris
Yes indeed, this is an old complaint. Just having an infix operator would be an improvement:
A dot B dot C
Not that I am suggesting dot in this regard ;) In particular, it wouldn't parse without spaces. What about division? Matlab has both / and \ for left and right matrix division and something like that could call solve instead of inverse, leading to some efficiencies. We also have both dot and tensordot, which raises the problem of interpretation when ndim > 2.
There's always the Haskell approach: *every* function can be an infix operator, just surround the name with backticks; functions with line-noise names (like + * - /) are infix by default. Not a good idea for python, I think. Anne.
Charles R Harris wrote:
On 3/24/07, *Travis Oliphant*
mailto:oliphant@ee.byu.edu> wrote: Every so often the idea of new operators comes up because of the need to do both "matrix-multiplication" and element-by-element multiplication.
I think this is one area where the current Python approach is not as nice because we have a limited set of operators to work with.
One thing I wonder is if we are being vocal enough with the Python 3000 crowd to try and get additional operators into the language itself.
What if we could get a few new operators into the language to help us. If we don't ask for it, it certainly won't happen. My experience is that the difficulty of using the '*' operator for both matrix multiplication and element-by-element multiplication depending on the class of the object is not especially robust. It makes it harder to write generic code, and we still haven't gotten everything completely right.
It is somewhat workable as it stands, but I think it would be nicer if we could have some "meta" operator that allowed an alternative definition of major operators. Something like @* for example (just picking a character that is already used for decorators).
Yes indeed, this is an old complaint. Just having an infix operator would be an improvement:
A dot B dot C
Not that I am suggesting dot in this regard ;) In particular, it wouldn't parse without spaces. What about division? Matlab has both / and \ for left and right matrix division and something like that could call solve instead of inverse, leading to some efficiencies.
Yes, thanks to a suggestion from Alan Isaac, this was implemented in PyMatrix (based on numarray and not yet converted to numpy). / served for one and // for the other. Regarding an additional multiply operator, I don't see the need for it. A matrix and and array are similar dut different animals. Colin W. We also
have both dot and tensordot, which raises the problem of interpretation when ndim > 2.
Chuck
------------------------------------------------------------------------
_______________________________________________ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
With the possible inclusion of generic functions in py3k I dont really
see the point of adding more operators. (While i do miss mat1 x mat2
from PDL).
mat3 = mat1.mm(mat2) or the like seems to be sufficient.
I find matrix multiplication annoying in the case of SVD reconstruction:
final = matrixmultiply(matrixmultiply(u, s), v)
A minor gripe though. I'm more inclined to err on the side of clean
python rather than more operators, especially since aforementioned
GF's will help with many cases
dpn
On 3/26/07, Colin J. Williams
Charles R Harris wrote:
On 3/24/07, *Travis Oliphant*
mailto:oliphant@ee.byu.edu> wrote: Every so often the idea of new operators comes up because of the need to do both "matrix-multiplication" and element-by-element multiplication.
I think this is one area where the current Python approach is not as nice because we have a limited set of operators to work with.
One thing I wonder is if we are being vocal enough with the Python 3000 crowd to try and get additional operators into the language itself.
What if we could get a few new operators into the language to help us. If we don't ask for it, it certainly won't happen. My experience is that the difficulty of using the '*' operator for both matrix multiplication and element-by-element multiplication depending on the class of the object is not especially robust. It makes it harder to write generic code, and we still haven't gotten everything completely right.
It is somewhat workable as it stands, but I think it would be nicer if we could have some "meta" operator that allowed an alternative definition of major operators. Something like @* for example (just picking a character that is already used for decorators).
Yes indeed, this is an old complaint. Just having an infix operator would be an improvement:
A dot B dot C
Not that I am suggesting dot in this regard ;) In particular, it wouldn't parse without spaces. What about division? Matlab has both / and \ for left and right matrix division and something like that could call solve instead of inverse, leading to some efficiencies.
Yes, thanks to a suggestion from Alan Isaac, this was implemented in PyMatrix (based on numarray and not yet converted to numpy). / served for one and // for the other.
Regarding an additional multiply operator, I don't see the need for it. A matrix and and array are similar dut different animals.
Colin W.
We also
have both dot and tensordot, which raises the problem of interpretation when ndim > 2.
Chuck
------------------------------------------------------------------------
_______________________________________________ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
_______________________________________________ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Em Seg, 2007-03-26 às 01:08 +1000, dpn escreveu:
With the possible inclusion of generic functions in py3k I dont really see the point of adding more operators. (While i do miss mat1 x mat2 from PDL).
mat3 = mat1.mm(mat2) or the like seems to be sufficient.
I find matrix multiplication annoying in the case of SVD reconstruction:
final = matrixmultiply(matrixmultiply(u, s), v)
Matrix multiplication is just too common in numerical linear algebra, one of the main areas for numpy/scipy. Even though I can get used with using dot (or matrixmultiply) to do it, I can easily see the benefit of having a special operator here. This will be beneficial for mathematicians that use numpy/scipy to prototype some ideas or to newcomers from Matlab. Paulo -- Paulo José da Silva e Silva Professor Assistente do Dep. de Ciência da Computação (Assistant Professor of the Computer Science Dept.) Universidade de São Paulo - Brazil e-mail: rsilva@ime.usp.br Web: http://www.ime.usp.br/~rsilva Teoria é o que não entendemos o (Theory is something we don't) suficiente para chamar de prática. (understand well enough to call practice)
On Sun, 25 Mar 2007, Paulo Jose da Silva e Silva apparently wrote:
Even though I can get used with using dot (or matrixmultiply) to do it, I can easily see the benefit of having a special operator here.
Some newer languages are taking advantage of the expressiveness of Unicode for math purposes. I believe somone on this list asked whether this might provide a way forward. Can it (taking a long view)? For example, it would be natural to use as operators the Unicode multiplication sign U+00D7 (×) and the Unicode dot operator U+22C5 (·). Cheers, Alan Isaac
On Mar 24, 3:48 pm, "Charles R Harris"
It is somewhat workable as it stands, but I think it would be nicer if we could have some "meta" operator that allowed an alternative definition of major operators. Something like @* for example (just picking a character that is already used for decorators).
Yes indeed, this is an old complaint. Just having an infix operator would be an improvement:
A dot B dot C
In Fortran 90 and later versions, A*B means element-wise multiplication, and there exist intrinsic functions such as matmul(A,B) and dot_product(A,B). One can define operators so that A .x. B .x. C is the same as matmul(A,matmul(B,C)) although I am unsure of the order of operations implied by the former syntax. The Matran http://www.cs.umd.edu/~stewart/matran/Matran.html package does this. I think Fortran's infix operators are a good solution but don't know if it can be carried over to Python.
participants (10)
-
Alan G Isaac
-
Anne Archibald
-
Beliavsky
-
Charles R Harris
-
Colin J. Williams
-
dpn
-
Matthieu Brucher
-
Paulo Jose da Silva e Silva
-
Sebastian Haase
-
Travis Oliphant