The partical lab is based on the following tools :
%magic
commandsthere are also libraries that we will not use, but can be very usefull for data-scientists:
This is a very important part - you'll find yourself spending more time reading doc than writting code !
Do not hesitate to go through the different help systems - available from here, ( look at the Help menu of this page, you will recognize the list )
it is organized in cells, each cell can either contain formatted text ( this cell! ), or a python program.
When executed, the result is displayed below the program cell
pwd
there is a slight difficult with python version 2 ane 3 co-exist. In practice, there is very little differences, unless you dig deep into the environment. At our level, the following command insures that both versions will behave in an equivalent manner.
from __future__ import print_function, division # this insures python 2 / python 3 compatibility
print( 'this course will last', 1 + 0.5, 'hours')
def fibonacci(n):
"the simplest (and inefficient) definition of the fibonacci series"
if n == 0 or n == 1:
f = 1
else:
f = fibonacci(n-1) + fibonacci(n-2)
return f
for i in range(10):
print (i+1, ':', fibonacci(i+1))
python is a simple program, one of its strength lies in all the libraries available - in particular scientific ones (see above)
Some are directly a part of the standard language (web interface, cryptogrphy, data-base, etc.) Others are developped independently, with the standard scientific stack : numpy, scipy, sympy, matplotlib, pandas (look at the help menu) and others more specific to a particular domain.
# numpy provides a fast computation of large numerical arrays
import numpy as np # (here we just give numpy the (standard) nick name np for easing the source code)
# matplotlib is the graphic library
# matplotlib.pylab is an easy to use utility, a bit reminiscent to matlab graphics
import matplotlib as mpl
import matplotlib.pylab as plt
# %matplotlib is a "magic" command to insert directly the graphics in the web page
%matplotlib inline
with these tools we can easily build and display complex functions
x = np.linspace(0,10,1000) # 1000 points equi distant from 0.0 to 10.0
y = np.cos(x) # takes the cos() values of all points in x
print('length of vectors, x:',len(x), 'y:',len(y))
print('433th value:', x[432], y[432]) # !!! array indices are from 0 to 999 !!
# and plot it - like in Excel !
plt.plot(x,y)
plt.plot(x[432],y[432], 'ro') # r is for red o is for round points