Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The beginning of the PEP (linked document) has a rationale for it, including an argument that matrix multiplication has a combination of features which distinguish it from other binary operations. Check it out. Like most Python PEPs it is quite readable. There are even alternative proposals and links to where the discussion of this issue has occurred.

It seems that the most fundamental reason is that matrix and memberwise multiplication are two distinct operations which use the same datatypes as operands and both have a very good claim to use of the * operator.

Also, just because a language is general purpose does not mean that it cannot support features which might be restricted in their use.

Two of the python's most popular uses are in scientific and numeric fields (see SciPy, NumPy and ipython). This operator seems like it would be very useful for improving readability in those areas which is probably reason enough to use it.

However, please resist the urge to just overload this new operator for something unrelated that you want. The point of infix operators is to improve the readability of code and lessen the cognitive load on the reader. Overloading an operator for a purpose which is not conventional goes exactly against this for... what benefit exactly?



Thanks. I understand its importance to scientific computing and I welcome the change. I was just wondering if matrix multiplication had more flexible uses, like `sum` does.

And the benefit of overloading is still readability, when carefully used and in a different domain. And sparingly. For the `@` operator I will be trying it as an "at" operator for accessing objects from a game map, or some sort of translation. If it performs well I may start using it in my pet projects. If it changes my life and enlightens everyone who gazes upon it, I may start using in production.

I do understand your worry and I promise to be extra careful.


> For the `@` operator I will be trying it as an "at" operator for accessing objects from a game map

I suppose you could use it for that that, but wouldn't that be a canonical case for indexing with []?


A little late, but I think the reply is worth it.

`[]` is for discrete elements. That's perfect for a tile game.

My idea with `@` is a sort of collision detection for continuous maps. `map @ (115.2, 23.5)` should return the object under that position.

This operation is useful on all sorts of interactions: "can I move there?", "what did the mouse click?", "do I have a line of sight?", etc.

I'm still thinking on how to chain those operations.




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: