Re:Introduction to Python for Computational Science and Engi...
by rishabguha on Friday November 25, 2016 @03:34PM
(#13039630)
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
[ Parent
| on HN ]
Re:Introduction to Python for Computational Science and Engi...
by sandGorgon on Friday November 25, 2016 @11:47PM
(#13041773)
everyone 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.
Re:Introduction to Python for Computational Science and Engi...
by stared on Saturday November 26, 2016 @08:20AM
(#13043363)
I 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.
Re:Introduction to Python for Computational Science and Engi...
by godelski on Friday November 25, 2016 @03:52PM
(#13039745)
I 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.
Re:Introduction to Python for Computational Science and Engi...
by noobermin on Friday November 25, 2016 @04:08PM
(#13039837)
a + 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.
Re:Introduction to Python for Computational Science and Engi...
by kazinator on Friday November 25, 2016 @06:14PM
(#13040577)
It 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
Re:Introduction to Python for Computational Science and Engi...
by dman on Friday November 25, 2016 @03:52PM
(#13039746)
Does @ work with numpy?
Re:Introduction to Python for Computational Science and Engi...
by jmbond on Friday November 25, 2016 @04:43PM
(#13040082)
Yes. See Notes section in the docs for numpy.matmul [1]
[1] https://docs.scipy.org/doc/numpy/reference/generated/numpy.m...