Hacker News new | ask | show | jobs
by MayeulC 1062 days ago
Hmm, I encountered or used all of these somewhere, but 4 days ago I learned something else: python natively supports complex numbers.

    a=1+3j
    b=a+4j
I encountered this when a friend noticed some weird syntax for a numpy meshgrid (via mgrid):

    np.mgrid[-1:1:5j]
3 comments

Numpy has a lot of these shortcuts that are quite opaque. For example np.r_ and np.c_

This one can be explained as "equivalent to np.linspace(-1, 1, 5)", i.e 5 evenly spaced points between -1 and 1. Normally the step size is an integer but with a complex "step" it switches the meaning from step size to number of equidistant points.

That parses to me as "given the list np.mgrid, return indexes -1 through 1, step by 5j". I know it's not, but that's what it looks like to me.
Repr prints source code that will (often) give you an equivalent object. I would be highly surprised if it got you The same object instance. == but not ===