Introduction to Python

python from Monty Python, not the snake


In [1]:
from IPython.display import Image
Image(url='https://www.python.org/static/community_logos/python-logo-master-v3-TM.png')


Out[1]:

In [2]:
from IPython.display import YouTubeVideo
YouTubeVideo("cV0tCphFMr8")

# jump to 1 min


Out[2]:

Pros & Cons of Python

Pros:

  • Free (as in beer & as in speech)
    • i.e. open source
  • Fast
  • Easy
  • A lot of toolboxes (called packages)

Cons:

  • not Matlab (some will argue this is on the wrong list)
  • a lot of toolboxes are written for Matlab

Python

  • indention sensitive
  • zero indexed!
    • Matlab is 1 indexed
  • comments #

In [ ]:
# simple for loop

for i in range(10):
    print i

Packages

A Toolbox is called a package needs to be imported in order to be used


In [3]:
import numpy as np
import pylab as plt

# only needed in IPython notebook and QT console
%matplotlib inline

In [ ]:

IPython

  • Interactive python!
  • enhanced python interpretor

IPython come in different ways:

- terminal
- qtconsole
- notebook

interacting with the shell

IPython interacts with the shell

- !
- %%bash

In [ ]:

Numpy


In [ ]:
adama = np.random.rand(10, 2) # generate an array with 10 * 2 random numbers between 0 & 1
adama

In [ ]:
plt.plot(adama)

In [ ]:
adama.T.shape