from notebook.services.config import ConfigManager
from IPython.paths import locate_profile
cm = ConfigManager(profile_dir=locate_profile(get_ipython().profile))
cm.update('livereveal', {
'theme': 'sky',
'transition': 'zoom',
'start_slideshow_at': 'selected',
})
{u'start_slideshow_at': 'selected', u'theme': 'sky', u'transition': 'zoom'}
Download and install Anaconda Python Distribution
(Optional) Download Academic license .skolkovotech.ru email is sufficient. It gives you access to the Intel MKL linear algebra package.
Run command in the terminal (if you have one, if you are on Windows, ask Evgeny Frolov what to do)
jupyter notebook
(on Mac & Linux, on Windows should work somehow as well).
You will get a new browser window with the list of your notebooks. If there none, you can create one!
You have to import several basic packages to start doing basic stuff for linear algebra and plotting.
There are a lot of useful Python packages in the world for almost every task: always look on the web
before writing your own code!
Basic libraries:
#This how their import looks like
%matplotlib inline
#To show everything in a browser
import numpy as np
import matplotlib.pyplot as plt
import scipy as sp
Notice the namespaces
import this
MATLAB is a well-known tool for doing numerical linear algebra computations, but it has many disadvantages.
If you are an experienced MATLAB user, then you can look at Numpy for MATLAB users.
Best to learn is practice!
for (i = 0, i < 5, i++){
printf("Hi! \n");
}
but like this:
#Some print 'Hi' code
for i in range(5):
print('Hi')
print('Hi3')
print('Hi2')
Hi Hi3 Hi Hi3 Hi Hi3 Hi Hi3 Hi Hi3 Hi2
from IPython.display import YouTubeVideo
#Long-long tutorial
YouTubeVideo('3Fp1zn5ao2M')
Numpy arrays is something that you need to know.
It is typically a bad idea to write your own array processing code!
#Create some numpy array and print it
import numpy as np
a = [1, 2, 3, 4]
np_a = np.array(a)
print np_a
print a
[1 2 3 4] [1, 2, 3, 4]
Let us do some arithmetics demo
#Do some arithmetics
b = 1.0
a = 1
c = a + b
print c, c ** 2, a/b
2.0 4.0 1.0
Let us do some loops demo
#Do some loop demo (i.e, create two lists and add them)
a = [1.0, 2.0, 3.0, 4.0]
b = [3.0, 4.0, 5.0, 6.0]
c = [0.0, 0.0, 0.0, 0.0]
for i in range(4):
c[i] = a[i] + b[i]
c = a + b
print c
[1.0, 2.0, 3.0, 4.0, 3.0, 4.0, 5.0, 6.0]
Adding two lists....
#Now we can add two lists
Adding two numpy arrays...
#Now we want to add two arrays
print np.array(a) * np.array(b) ** 2
[ 9. 32. 75. 144.]
#Do some matrix-by-vector operations
a = np.array([[1.0, 0.5, 0.5], [0.0, 1.0, 2.0], [3.0, 4.0, 5.0]])
v = np.random.randn(3)
print a.dot(v) #@
print a * v
[-1.63638585 -0.41324712 -6.42705844] [[-1.26816793 -0.52981229 0.16159436] [-0. -1.05962458 0.64637746] [-3.80450379 -4.23849831 1.61594365]]
Let us create some functions!
def mysum(a, b):
c = np.zeros(len(a)) #All zeros
for i in xrange(len(c)):
c[i] = a[i] + b[i]
return c
And add two large arrays!
M = 10 ** 5
a = np.ones(M) #All ones
%timeit c = mysum(a, a) #IPython magic function for timing
%timeit c = a + a ** 2 #Numpy built-in function
10 loops, best of 3: 35.1 ms per loop 10000 loops, best of 3: 73.6 µs per loop
from numba import jit
@jit(nopython=True)
def mysum_nb(a, b):
c = np.zeros(len(a))
for i in range(len(a)):
c[i] = a[i] + b[i] ** 3 + a[i] * b[i]
M = 10 ** 5
a = np.ones(M) #All ones
%timeit c = mysum_nb(a, a) #IPython magic function for timing
%timeit c = a + a ** 3 + a * a#Numpy built-in function
The slowest run took 1203.02 times longer than the fastest. This could mean that an intermediate result is being cached 10000 loops, best of 3: 133 µs per loop 1000 loops, best of 3: 1.01 ms per loop
To do plotting, you have to put in a preamble.
%matplotlib inline
import matplotlib.pyplot as plt
import seaborn as sns #For prettier plots
import numpy as np
Our main object will be matrix.
from IPython.display import Image
i = Image(filename='TheMatrix.jpg', retina = True)
$A$ is an $n \times m$ matrix. $v$ is an $m \times 1$ matrix (vector).
$$
y = A x,
$$
y is a vector of length $n$.
#Multiply matrix by vector here
Stellar is still here.
from IPython.core.display import HTML
def css_styling():
styles = open("./styles/custom.css", "r").read()
return HTML(styles)
css_styling()