Exercise 1

  1. Create a uniform subdivision of the interval -1.3 to 2.5 with 64 subdivisions.
  2. Generate an array of length $3n$ filled with the cyclic pattern 1, 2, 3.
  3. Create an array of the first 10 odd integers.
  4. Create a 10 x 10 arrays of zeros and then "frame" it with a border of ones.
  5. Create an 8 x 8 array with a checkerboard pattern of zeros and ones using a slicing+striding approach.

Exercise 2

  1. Try using the dot function on a vector-vector, matrix-vector and matrix-matrix example. (This may seem simple but it's good to see how the results differ in each case.)
  2. Create a plot of $x^2 \cdot \sin(1/x^2) + x$ on the interval $[-1, 1]$ using 250 points. Remember to label the axes!
  3. Create a semilogy plot of the relative difference of $1 / (1+x^2)$ and $1/x^2$ on the interval $[5, 25]$. (The relative difference of numbers $a$ and $b$ is given by $|1-a/b|$. It provides a better sense of error relative to the order of magnitudes of $a$ and $b$.)
  4. It was mentioned that many common functions are availible in vectorized form. It turns out that Scipy also has many less common, special functions. Take a look at the extensive list here! Try looking for some interesting ones you recognize (or maybe don't recognize!) and either plug in a few numbers or plot them.

Exercise 3

  1. Create a color plot of $\sin(x) \sin(y)$ on the interval $[-\pi, \pi] \times [-\pi, \pi]$.
  2. Create a function which creates an $n \times n$ array with $(i,j)$-entry equal to $i+j$.

Exercise 4

  1. Evaluate $\cos$ and $\sin$ on the interval $[0, 1]$ and then stack the results into a tall array with rows being the $(\cos(x), \sin(x))$ entries.
  2. Create a random $3 \times 5$ array using the np.random.rand(3, 5) function and compute: the sum of all the entries, the sum of the rows and the sum of the columns. (Just like sorted had an optional key= argument, many Numpy functions have an optional axis= argument!)
  3. Create a random $5 \times 5$ array using the function np.random.rand(5, 5). We want to sort the rows according to the second column. Try combining array slicing + argsort + indexing to do this.