7 ms·
I hate the new @ operator for matrix multiplication, it just looks ugly. (And I use numpy matrix math all the time.) But whatever.
by jason_s 11y ago
I hate the new @ operator for matrix multiplication, it just looks ugly. (And I use numpy matrix math all the time.) But whatever.
- inglor 11y agoAs a fellow numpy user - why? I would love having sugar for this, I use it all the time. Introducing a single operator to overload seems odd but it's definitely a pragmatic solution to making code more readable. What would you do instead?
- Sanddancer 11y agoPersonally, I'd have made it a diglyph of some sort, like :* or ^*, to make it obvious to someone looking at python math code for the first time that this is a multiplication operator. @ just leaves a weird taste here.
- JoshTriplett 11y agoAgreed; this needs an operator, but it doesn't need a single-character operator, and the operator should have had * in it.
- ngoldbaum 11y agoThe pros and cons of different operator possibilities are discussed extensively in the PEP that added the matrix multiplication operator.
- yoha 11y agoDirect link: http://legacy.python.org/dev/peps/pep-0465/#choice-of-operator http://legacy.python.org/dev/peps/pep-0465/#choice-of-operat...
- KeytarHero 11y agoI love the snark in that PEP: > APL apparently used +.× , which by combining a multi-character token, confusing attribute-access-like . syntax, and a unicode character, ranks somewhere below U+2603 SNOWMAN on our candidate list. and then later, one of the reasons @ is better than the alternatives: > Whatever, we have to pick something.
- mixmastamyk 11y agoWhat about the & char?
- ngoldbaum 11y ago& is the bitwise and operator.
- mixmastamyk 11y agoYep, forgot thanks.
- JoshTriplett 11y agoNot particularly well, though. No actual explanation was given for rejecting ^(star), and :(star) wasn't even mentioned. (Aside: HN really needs a better way to escape star inline in text.)
- sdenton4 11y agoIt sounded like there was a bit of general preference for a single-character operator, which is a sentiment I can get behind.
- toolslive 11y agoOCaml has * for int multiplication and * . for float multiplication. you cannot overload but you can define your own, so people tend to do things like define *: for complex multiplication.
- noreasonw 11y agoIn R %*% is matrix multiplication.
- eliben 11y agoWhat alternative would you propose? Given that having an operator for this was deemed important for more readable numeric code, and that * was already taken, there weren't too many fabulous choices left.
- perlgeek 11y agoAlso it feels like wasting a character on something that only a small number of users are likely going to need.
- sherjilozair 11y agoNot necessarily. You can overload @ to do some other kind of object combination, which fits your paradigm better. You're not tied to using it for matrix multiplication.
- mcherm 11y agohttps://www.python.org/dev/peps/pep-0465/#choice-of-operator https://www.python.org/dev/peps/pep-0465/#choice-of-operator
- sdenton4 11y agoPython 3.5: In which your email address became syntactically correct.