Exercises rating:

★☆☆ - You should be able to do it based on Python knowledge plus the text.

★★☆ - You will need to do extra thinking and some extra reading/searching.

★★★ - The answer is difficult to find by a simple search, requires you to do a considerable amount of extra work by yourself (feel free to ignore these exercises if you're short on time).

Note: Some of the exercises in this section are way beyond what we cover. Instead, the exercises are a review of your general python programming knowledge. You can safely ignore these exercises, they are not necessary for what we learn later.

`.mean()`

In [ ]:

```
```

`by_zero.py`

```
def div_xy(x, y):
return x / y
def div_by_zero(x):
return div_xy(x, 0.0)
```

** import** the module and execute the

`div_xy`

P.S. You do not need to worry about an ** __init__.py** file if the module is in the same directory.

In [ ]:

```
```

In [ ]:

```
```

Try to explain the differences between what you see.

In [ ]:

```
%xmode Plain
by_zero.div_by_zero(3)
```

In [ ]:

```
%xmode Context
by_zero.div_by_zero(3)
```

In [ ]:

```
%xmode Verbose
by_zero.div_by_zero(3)
```

`%pdb on`

to print out the value of `y`

(inside `div_xy`

) just before the division by zero. (★★★)¶In [ ]:

```
import by_zero
by_zero.div_by_zero(3)
```

`%timeit`

to time a function that sums the elements of a list, compare it with `np.sum`

(★★☆)¶You can use ** np.arange(1024)** to create a list of the first 1024 integers.
Here is a start (this exercise ought to take a while to run):

In [ ]:

```
def sums_all(l):
pass
```

In [ ]:

```
import numpy as np
long_list = np.arange(1024)
%timeit np.sum(long_list)
%timeit # your function
```

`%prun`

to profile the function you wrote in exercise 5. (★★★)¶In [ ]:

```
import numpy as np
long_list = np.arange(32256)
```