Rock It 《ML》JupyterLab 【丁】Code《五》

易經』之難解,不在『卦』

『象』的

組合

後人以「無極生太極、太極生兩儀、兩儀生四象、四象生八卦、八卦六十四卦」來解釋的卦的構成。

  1. 無極
  2. 太極:(☯)代表一,傳統的太極圖代表了陰陽互補;
  3. 兩儀:一分為二,分開了陰和陽,即是兩儀;
  4. 四象:二分為四,即是四象:太陽、少陽、少陰、太陰;
  5. 八卦:四分為八,即是八卦:乾、兌、離、震、巽、坎、艮、坤;
  6. 六十四卦:兩個八卦相疊,即成八八六十四卦。

 

有什麼繁文縟節,而在『義』與『理』交織錯綜複雜;以至於其『數』生玄外之音也!

『派生』 Python 之易學,非因『關鍵字』少,實源『禪味』單純︰

吉多的 Python 『非同』於其他程式語言,居然把『空白』符號寫進了它的『文法』裡,竟然用『對齊的空白』表示程式區塊。如是種種『見地』,匯聚成一條稱作『非同的』pythonic  Way 大道。吉多他的『中心思想』,集中的表現在由 Tim Peters 先生所寫的『 Python 的禪』,收錄在『 this模組 module 裡︰

import this

The Zen of Python, by Tim Peters

Beautiful is better than ugly.
美比醜好

Explicit is better than implicit.
明白比晦暗好

Simple is better than complex.
簡單比複雜好

Complex is better than complicated.
複雜比複雜化好

Flat is better than nested.
平直比疊套好

Sparse is better than dense.
薄落比濃縮好

Readability counts.
可讀性能加分

Special cases aren’t special enough to break the rules.
特例不夠特殊到能夠破壞規矩

Although practicality beats purity.
雖然獨特性能打敗純粹性

Errors should never pass silently.
錯誤不該無言放過

Unless explicitly silenced.
除非指明它是靜默寡詞

In the face of ambiguity, refuse the temptation to guess.
面對含混,拒絕揣測意圖

There should be one– and preferably only one –obvious way to do it.
總有一個,最好是唯一的一個,明白的作法

Although that way may not be obvious at first unless you’re Dutch.
即使起初那條道路並不明顯,除非你很「好辯」

Now is better than never.
當下好於從不

Although never is often better than *right* now.
雖然從不也常常好過馬上

If the implementation is hard to explain, it’s a bad idea.
如果一件事很難說明怎麼做成的,那這個想法不好

If the implementation is easy to explain, it may be a good idea.
反之如果一件事怎麼做,很容易說明白,也許是個好想法

Namespaces are one honking great idea — let’s do more of those!
「名字空間」的理念──響亮著的偉大號角,就讓我們多多用它吧

─── 摘自《『騛罿』── 非同的禪!!

 

說道『話頭』機鋒,『語意』通常耐人尋味也!

故善學者,往往假借各種『工具』

Variable Inspector

lantern.VariableInspector()

variableinspector.png

 

/birdseye

Graphical Python debugger which lets you easily view the values of all evaluated expressions https://birdseye.readthedocs.io

logo birdseye

Build Status Supports Python versions 2.7, 3.5, and 3.6 Join the chat at https://gitter.im/python_birdseye/Lobby

birdseye is a Python debugger which records the values of expressions in a function call and lets you easily view them after the function exits. For example:

Hovering over expressions

Rather than stepping through lines, move back and forth through loop iterations and see how the values of selected expressions change:

Stepping through loop iterations

See which expressions raise exceptions, even if they’re suppressed:

Exception highlighting

※ 註︰

Jupyter/IPython notebooks

First, load the birdseye extension, using either %load_ext birdseye in a notebook cell or by adding 'birdseye' to the list c.InteractiveShellApp.extensions in your IPython configuration file, e.g. ~/.ipython/profile_default/ipython_config.py.

Use the cell magic %%eye at the top of a notebook cell to trace that cell. When you run the cell and it finishes executing, a frame should appear underneath with the traced code.

Jupyter notebook screenshot

Hovering over an expression should show the value at the bottom of the frame. This requires the bottom of the frame being visible. Sometimes notebooks fold long output (which would include the birdseye frame) into a limited space – if that happens, click the space just left of the output. You can also resize the frame by dragging the bar at the bottom, or click ‘Open in new tab’ just above the frame.

For convenience, the cell magic automatically starts a birdseye server in the background. You can configure this by settings attributes on BirdsEyeMagics, e.g. with:

%config BirdsEyeMagics.port = 7778

in a cell or:

c.BirdsEyeMagics.port = 7778

 

 

/callgraph

Magic to display dynamic call graphs of Python function calls

Callgraph Magic

Latest PyPI Version Documentation Status License Supported Python Versions

Callgraph is a Python package that defines a decorator, and Jupyter magic, to draw dynamic call graphs of Python function calls.

It’s intended for classroom use, but may also be useful for self-guided exploration.

The package defines a Jupyter IPython magic, %callgraph, that displays a call graph within a Jupyter cell:

from functools import lru_cache

@lru_cache()
def lev(a, b):
    if "" in (a, b):
        return len(a) + len(b)

    candidates = []
    if a[0] == b[0]:
        candidates.append(lev(a[1:], b[1:]))
    else:
        candidates.append(lev(a[1:], b[1:]) + 1)
    candidates.append(lev(a, b[1:]) + 1)
    candidates.append(lev(a[1:], b) + 1)
    return min(candidates)

%callgraph -w10 lev("big", "dog"); lev("dig", "dog")

image0

It also provides a Python decorator, callgraph.decorator, that instruments a function to collect call graph information and render the result.

Jupyter / IPython Usage

$ sudo pip3 install callgraph

In a Jupyter IPython notebook:

%load_ext callgraph

def nchoosek(n, k):
    if k == 0:
        return 1
    if n == k:
        return 1
    return nchoosek(n - 1, k - 1) + nchoosek(n - 1, k)

%callgraph nchoosek(4, 2)

 

 

直攻『光明頂』呦◎