In [2]:

```
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',
})
```

Out[2]:

- 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!

- Notebook consists of
**cells**of different types - Code in the cells is executed by pressing
**Shift + Enter** - To add a cell, use
**Insert**in the menu - To edit the cell, double-click on it.

- Notebooks are good for short snipplets of the code
- Big codes are typically written in a separate
**.py**files and used as**packages** - It is a good idea to use Notebooks for the presentation of the final results of your computation

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:

**numpy**(for doing matrix & vector stuff)**matplotlib**(for doing plotting), prettyplotlib (for nice plotting)**scipy**(a huge math library, we will use it for sparse matrices)

In [25]:

```
#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**

In [ ]:

```
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.

- Indexing from 0
- [ ] instead of ( ) for array element
- Python is a powerful and flexible programming language :)

Best to learn is practice!

- Use 4 whitespaces to denote a codeblock

**Not like this!!**

but like this:`for (i = 0, i < 5, i++){ printf("Hi! \n"); }`

In [6]:

```
#Some print 'Hi' code
for i in range(5):
print('Hi')
print('Hi3')
print('Hi2')
```

In [7]:

```
from IPython.display import YouTubeVideo
#Long-long tutorial
YouTubeVideo('3Fp1zn5ao2M')
```

Out[7]:

Numpy arrays is something that you need to know.

It is typically a bad idea to write your own array processing code!

In [17]:

```
#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
```

Let us do some arithmetics demo

In [21]:

```
#Do some arithmetics
b = 1.0
a = 1
c = a + b
print c, c ** 2, a/b
```

Let us do some loops demo

In [26]:

```
#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
```

Adding two lists....

In [20]:

```
#Now we can add two lists
```

Adding two numpy arrays...

In [31]:

```
#Now we want to add two arrays
print np.array(a) * np.array(b) ** 2
```

In [37]:

```
#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
```

Let us create some functions!

In [39]:

```
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!

In [40]:

```
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
```

**Why is the difference?**- Actually, there are many ways to solve the problem (Numpy, Cython, f2py, numba)

In [44]:

```
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
```

To do plotting, you have to put in a preamble.

In [45]:

```
%matplotlib inline
import matplotlib.pyplot as plt
import seaborn as sns #For prettier plots
import numpy as np
```

Our main object will be **matrix**.

In [1]:

```
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$.

In [17]:

```
#Multiply matrix by vector here
```

- Install & try to test Anaconda Python distribution
- Bother TAs with questions
- First homework to be delivered end of this week.

Stellar is still here.

In [2]:

```
from IPython.core.display import HTML
def css_styling():
styles = open("./styles/custom.css", "r").read()
return HTML(styles)
css_styling()
```

Out[2]: