numpy: Exercises¶

1. Implement a function that takes a d dimensional vector x returns their Euclidean norm.

Hint

The Euclidean norm of a vector is the square root of its dot product with itself.

2. Implement a function that takes two d dimensional vectors x and z and returns their Euclidean distance.

Hint

Can you re-use the solution of the previous exercise?

3. Implement a function that takes a matrix A and an integer k, and returns A elevated to the k th power.

4. Write a Python program that plots the data here:

https://drive.google.com/open?id=0B0wILN942aEVVlk4TS1WaDItVU0


Every row has an experiment ID and a value; there are 10 experiments, and 100 values (rows) per experiment. For each experiment, plot its values as a time series.

The plot the average time series, i.e. the average curve, where the average is taken over all experiments.

Hint

Use matplotlib.pyplot and the plot(x, y) function, as done in the examples above, to plot the ten curves and their mean.

5. Implement the Power Iteration method for finding the largest eigenvalue and eigenvector of a matrix, as described in the first paragraph of:

Check that it matches the results given by the eig() method of the linalg module.

6. Implement the Gram-Schmidt orthogonalization routine, described here:

7. Given the iris dataset, compute the covariance matrix of the petal lenght and petal widht for the iris setosa rows.

Hint

The covariance matrix is defined here: