4 ms·
IMO, Python 3's support for matrix multiplication using the @ operator is itself worth the cost of admission. Much of technical computing is just implementing a
by rishabguha 10y ago
IMO, Python 3's support for matrix multiplication using the @ operator is itself worth the cost of admission. Much of technical computing is just implementing algorithms that use linear algebra extensively, and if you're coming from matlab littering your code with dot(dot(X,Y),Z) is a real pain
- godelski 10y agoI actually see np.dot(np.dot(x,y),z) as easier to read and remember. It is more explicit in what it is doing. Being explicit is a good thing.
- noobermin 10y agoa + 4*(x-y) + b**5 vs (+ a (* 4 (- x y )) (expt b 5 )) Sometimes, as arithmetic with lisp shows, conciseness is better. Also, it isn't being more explicit than it is being more verbose.
- kazinator 10y agoIt is abosolutely being more explicit. It's being more explicit that (expt b 5) is a unit that forms a single argument in the + form. This is implicit in a + b ** 5 according to a precedence rule between the and + operator, which is hidden in the parser's implementation and in documentation thereof. Well, the white-spacing a + b**5 suggests it. But the suggestions produced by insignificant whitespace can be mere wishful thinking: int* x, y; // two C pointers? not! Speaking of whitespace, also have the advantage of there being multiple ways to split the expression into multiple lines, all conforming to a very clear, simple formatting rule: (+ a (* 4 (- x y)) (expt b 5)) (+ a (* 4 (- x y)) (expt b 5)) Fully expanded, every term on separate line: (+ a (* 4 (- x y)) (expt b 5)) In this manner, we can write complex expressions that would be quite unreadable in infix, requiring break-up into intermediate temporaries. We almost have a circuit diagram now with "gates" for the operations: a three input + gate, etc: ____ / |- a | | ____ --| + |-----/ |- 4 | | | * | ____ \____|- | |-----/ |- x ` \____| | - | | \____|- y | _____ `--/ |- b | expt| \_____|- 5
- deleted 10y ago[deleted]
- dman 10y agoDoes @ work with numpy?
- sandGorgon 10y agoeveryone i know does matrix multiplication using numpy or pandas and conveniently abstracts away the need to do language conversion. same thing with asyncio vs gevent and tons of otger features. I say this again - there are industrial strength packages and libraries for py2 that gives all the power and convenience that you think you get in py3. Perhaps even better tested and used in production.
- stared 10y agoI find @ nice. But still, even in Python 3 if you use np.matrix (instead of np.array), multiplication works. And if not, then dot-method is way clearer than dot-function.