In [1]:

```
from IPython.core.display import Image
Image(filename='logo.png', width=600)
```

Out[1]:

IPython Notebook is a cell-based development environment. Each block of code (or text) can be run independently, and all cells share the same kernel. Each evaluated cell is stored in the `In`

array, and the corresponding output is stored in `Out`

.

Given $a \in \mathbb{R}^D$, compute $\sum_{i = 1}^D a[i]^2$.

In [2]:

```
def sum_of_squares(a):
return np.sum(a**2)
```

In [3]:

```
foo = np.array([1, 3, 5])
sum_of_squares(foo)
```

Out[3]:

In [4]:

```
print Out[3] + 4
```

In [6]:

```
# With the --pylab inline option, matplotlib plots are inline as cell output
w = np.linspace(0, 4*pi, 1000)
plt.plot(w, np.sin(w))
```

Out[6]:

IPython will keep track of the members of all of the modules you import and give you tab-completion. It will also tab-complete function arguments and provide help() documentation inline.

In [7]:

```
import scipy.signal
```

In [ ]:

```
scipy.signal.fi
```

In [8]:

```
help(scipy.signal.firwin)
```

IPython includes "magics", which are provide bonus useful functionality in IPython only.

In [9]:

```
# %timeit runs a single line a bunch of times and reports the average run time
%timeit np.arange(1000)
%timeit xrange(1000)
```

In [10]:

```
%%prun
# prun runs Python's profiler on the current cell
N = 1e5
scipy.signal.fftconvolve(np.random.rand(N), np.random.rand(N))
```

In [11]:

```
# Not a magic, but IPython also allows for running shell commands
!ls -lh
```

In [12]:

```
# The Python-Matlab bridge can be used as a magic
import pymatbridge as pymat
ip = get_ipython()
pymat.load_ipython_extension(ip)
```

In [13]:

```
# Python variable - a filter cutoff
Wn = .2
```

In [14]:

```
%%matlab -i Wn -o b
b = fir1(30, Wn);
```

In [15]:

```
import scipy.signal
w, h = scipy.signal.freqz(b);
plt.plot(w, np.abs(h))
```

Out[15]:

- .ipynb files - human-readable json with all output cached
- Autosaving
- .py files with --script option
- HTML, PDF, LaTeX, etc.
- nbviewer to view notebooks without IPython installed http://nbviewer.ipython.org/github/craffel/crucialpython/blob/master/week1/demo.ipynb