Lab 01
Introduction to Python/Jupyter



Yuyuan Yuan, Yuehchou Lee

National Taiwan University

Introduction

This is a course about computational mathematics.

You guys will learn some knowledge about
numerical methods and coding skills to implement them.

Course Website

All exercise info and lectures will be posted on this website.

https://yuanyuyuan.github.io/itcm/

Before we get started...

Does anyone know C/C++? MATLAB? Python?
CLI(Command-line interface)? Github?

The programming language
we're going to used is ...

  • It's an interpreted, high-level programming language created by Guido van Rossum in 1991.

  • Easy to use. Simple syntax is just like Enlish language.

  • Interpreted, object-oriented, cross-platform language.

What Python can do?

  • Scientific Computing

  • Web Development

  • Business Applications

  • Data Science

... and with many powerful libraries!

Easily install new packages with pip!


    $ pip install PACKAGE_NAME
                                

An Alternative to MATLAB

Machine Learning Toolkit

Including the hottest
Deep Learning!

Install Python on your laptop!

For beginners, we usually recommend Anaconda.

Install on Windows

Install on macOS

How to use?

Launch anaconda on Windows

Launch terminal on macOS

REPL

  • R ead the user input

  • E valuate the code

  • P rint the results instantly

  • L oop back to first step

REPL let you easily talk to your computer in Python!

Let's try it!


    $ python

    Python 3.7.4 (default, Jul 16 2019, 07:12:58)
    [GCC 9.1.0] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>>
                        

    >>> print("Hello, Python!")
    Hello, Python!
                        

    >>> exit() # type exit() or press CTRL+D to exit
                        

In addition to Python,
we're going to use ...

Jupyter Notebook

Launch Jupyter Notebook

Just launch Anaconda Prompt(windows) or Terminal(macOS)
and type in the following command.

    $ jupyter notebook
                        

Click me to try it!

Assignments

We use Github to manage our assignments.

How to?

Register A Github Account

Create Your New Repo

Make It Private And Named itcm-notebooks

Invite TAs (yuanyuyuan, yuehchou) into Your Collaborators

Now Launch
Anaconda Prompt(windows)
or Terminal(macOS)

And then launch
Jupyter Notebook


    $ jupyter notebook
                        

Then run terminal from
your Jupyter Notebook

New → Terminal

Install Git


    $ conda install git

    Collecting package metadata (current_repodata.json): done
    Solving environment: done

    ## Package Plan ##

      environment location: /usr/local/anaconda3

      added / updated specs:
        - git
    ...
                        

Clone TAs' Repo

Clone the sample repo and add TA's repo to upstream.


    $ git clone https://github.com/yuanyuyuan/itcm-notebooks
    $ cd itcm-notebooks
    $ git remote add upstream https://github.com/yuanyuyuan/itcm-notebooks
                        

Change the orgin of this repo to yours. Fill in YOUR_ACCONUT below!


    $ git remote set-url origin https://github.com/YOUR_ACCOUNT/itcm-notebooks
                        

Sync with TAs' Repo

Whenever TAs announce new assigments, just sync with the upstream(TAs' repo)!


    $ git fetch upstream
    $ git merge upstream/master --no-edit
                            

Maintain Your Codes

Change working directory to your repo on your NB.


    $ cd YOUR_REPO_PATH  # e.g. cd itcm-notebooks
                        

Copy lab-1/exercise to lab-1/answers and finish it.


    $ cp -r LAB_EXERCISE_FOLDER LAB_ANSWER_FOLDER  # e.g. cp -r lab-1/exercise lab-1/answers
                        

After finish your answer, git add/commit/push your files!


    $ git add FILES_TO_SUBMIT         # e.g. git add lab-1/answers
    $ git commit -m "COMMIT_MESSAGE"  # e.g. git commit -m "finish my answers of lab-1 exercise"
    $ git push                        # submit new files to your github repo!
                        

Please commit your answers only!

Do NOT commit hands-on and exercise!

Do NOT commit hands-on and exercise!

Do NOT commit hands-on and exercise!

Remember after you
git add some files ...

Always Check Before You Commit!


    $ git status
    On branch master
    Your branch is up to date with 'origin/master'.

    Changes to be committed:
      (use "git restore --staged <file>..." to unstage)
            new file:   answers/exercise1.ipynb
            new file:   answers/exercise2.ipynb
            new file:   answers/jupyter.png

                        

In Case You Still Committed Wrongly...


    $ git reset master^
                        

Then it will reset to the status before previous commit.

In Case of Misfortune

Google the problem and solve it by yourself or find TA...

The Last But Not Least

Let us know your repo by finishing this form.

Goal

In the end of this course, no matter what grade you get, no matter what you will forget, you can show off your works!

Just Post A Link Like This!

The End.
Any Questions?