Start here!

This very brief introduction is designed as an overview of Python and its ecosystem. Since the journey is long, we won't spend much time here. Time is indeed too limited a resource to be lavishly squandered. So the purpose of this notebook is to get you and your machine ready for what is to come in the lessons ahead. Let us start with you, then we deal with the least complicated part (the machine).

Why Python?

Most human beings don't simply go around doing things. For them, motivation is absolutely necessary. These matters only get worse when one considers which programming language one should learn. So why should you spend your time trying to learn Python? Here are some reasons I can give you.

1. Readability.

Python's simple and highly readable syntax allows you to learn it really fast compared to other languages like C++ or Java. This is particularly true if you have never programmed before. You might even be able to thoroughly teach it yourself in 21 days. Jokes apart, readability is an important feature of Python by design, as stated by Guido van Rossum, the creator of the language. Pyhton's high readability often translates in practice into smaller and simpler code and lower development times when compared to other languages. It also means that many of the routine tasks you will perform in practice, like scripting, will be more effective with Python than most other languages.

2. A vast ecosystem.

No matter what computational task you have in mind, there is a Python module that accomplishes it. No matter what question you might have about a particular construct using any of these Python modules, someone has likely made that question before you, and this question has probably been thoroughly answered by a member of Python's huge community.

of the Python modules that we shall use in this course. A Python module can be seen as a toolcase providing functionality to solve a specific class of problems. Thus, the math module includes mathematical functions commonly used in science and engineering. Similarly, the random module provides methods for generating pseudorandom numbers. So here are some of the most commonly used modules:

  1. Core Python (the basic language)
  2. Numpy (python's numeric toolbox, similar to matlab)
  3. Matplotlib (for plots)
  4. Pandas (datasets and data analysis, equivalent to many of R's functionality)
  5. Scikit-learn (machine learning)

The first module is just the Python language as is. It provides basic functionality to implement general purpose algorithms. On the other hand, the last two modules are of particular interest for scientists and engineers. The numpy module includes all kinds of mathematical functions and devices implemented in a numerically efficient way. It will be our preferred tool for numerical analysis. The Matplotlib.pyplot module provides MATLAB-like functions for paper quality plots. It should be noted that we structured this document in this way for purely pedagogical reasons, with the aim to get you programming on the fly.

Another important point to be made is that we will be using python 3 in these lectures. While it is not our purpose here to discuss where python 3 is not backwards compatible with python 2, you should be aware that code written in one version of python will not necessarily work the way it would in another version. Therefore, to make sure that you are fully compatible with all the technical specifications of this course, we strongly recommend you to download and install the Anaconda distribution of python. In what follows, we guide you through the installation process.

1. Installing and running Anaconda

Go to the the Anaconda webpage, https://www.continuum.io/downloads.


In [1]:
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!

In [ ]: