Thursday, February 21, 2019

Jupyter 101

Jupyter notebook : IPython
  • jupyter.org
  • Install Jupyter notebook
  • Install Anaconda
  • Anaconda.org Cloud
  • Anaconda packages using pip
  • Anaconda packages development in GitHub
  • Anaconda documentation
  • # anaconda packages installation
    # conda install pip
    % conda install -c anaconda pip
    % pip install package-name 
    # to launch
    % jupyter notebook
    # Or, launch from Anaconda Navigator
    # to install new packages
    # import sys
    # !{sys.executable} -m pip install newpackage
    
    Basics
  • Dashboard
  •    File
       Run
       New
    
  • Menu Bar
  • Tool Bar
  • Create new notebook
  • Rename notebook
  • Save notebook
  • Load notebook and "run all"
  • Cell : command mode, edit mode, raw NB convert mode
  • shortcuts : command palette
  • Shift-Enter
  • Example : code cell
    import numpy as np
    print (np.__version__)
    
    import sqlite3
    # from IPython.utils.path import get_ipython_dir # moved to IPython.paths
    import pprint
    from IPython.paths import get_ipython_dir
    hist_file = '%s/profile_default/history.sqlite' % get_ipython_dir()
    print (hist_file)
    
    Example : markdown cell (use print preview or shift-enter, double click to edit)
    [esc]+m
    %matplotlib qt
    %matplotlib auto
    %matplotlib inline
    %matplotlib -l
    %matplotlib --list
    [esc]+o           ## toggle output
    %load_ext?
    %time?
    !ls
    !dir
    !pwd
    
    ### Heading1
    ## Heading2
    # Heading1
     [Link to this page](http://www.google.com)
    
    1. first
        1. first of first
    2. second
    
    - bullet
        - bullet
    *italic*
    _italic_
    **bold**
    ***italic and bold***
    ~~strike through~~
    
    Example : Markdown Table
    # use http://www.tablesgenerator.com/markdown_tables
    #     to generate the markdown code for tables
    # copy the table form Excel or Google Sheet
    #     paste to the table on This Page
    #     and click [Generate]
    # copy the Result code to your Jupyter Notebook Markdown Cell
    
    Example : Fun with matplotlib
    import matplotlib.pyplot as plt
    t = np.ones(30)
    # red dashes, blue squares and green triangles
    plt.plot(t, t, 'r--', t, t**2, 'bs', t, t**3, 'g^')
    plt.show()
    
    Example : Visualize Big O Notation
    import numpy as np
    import matplotlib.pyplot as plt
    n = np.ones(40)
    t = np.arange(1.,20.,0.5)
    lineflt = plt.plot(t, t*0, 'g--' )
    linelog = plt.plot(t, np.log(t), color='#990000', label="O(Log n)")
    #plt.plot(t, np.log(t), 'b', t, t, 'r', t, t*t,)
    linelin = plt.plot(t,t, label="O(n) linear", color='orange')
    linenlg = plt.plot(t,t*np.log(t), label="O(n Log n)")
    linen2n = plt.plot(t,t*t, 'c', label="O(n^2)")
    linen3n = plt.plot(t,t**3, color='#ffa500', label="O(n^3)")
    line2tn = plt.plot(t,2**t, 'm', label="O(2^n)")
    plt.ylim(0,100)
    plt.legend()
    plt.grid(True)
    # plt.ylabel('some numbers')
    plt.show()
    

    No comments:

    Post a Comment