Import numpy with the alias np and print its version number
Create a numpy array with integer values ranging from -30 to +30 (inclusive) and print it.
Create a similar array to above, but make the values type float64, and print it.
Rather than creating the array of desired type, use numpy's astype() function to convert your array to type float16
Compute the length of your array using numpy functions.
Create a $10 \times 1$ random vector using rand() function in the numpy's random module.
Create two $10 \times 1$ random vectors and compute their dot product. Note, you may need to transpose one ofthe appropriately depending on whether your array is 1D or 2D.
Create two $10 \times 1$ random vectors and convert them to float16 precision, and test homogeneity of the dot product in this precision using array programming. I.e., test if $(\alpha \mathbf x) \cdot \mathbf y = \alpha (\mathbf x \cdot \mathbf y)$. Use $\alpha = 100$. If the test fails, compute the length of the error. Try rerunning it multiple times.
Demonstrate the conversion of a python list to a numpy array and the conversion of a numpy array to a list by converting then printing the types.
Use numpy's reshape function to convert the python list [0,1,2,3,4,5] to a numpy array of shape (6,1) and an array of shape (3,2). Print the conversion results, their shapes, and the number of dimensions for each.
Demonstrate the use of reshape both as a member of the numpy class and as a member of the array class.
Convert your (3,2) array back to a python list and observe the result. Show how to include use of numpy's flatten function to get back to the plain list like you started with.
Test what the division operator does for a numpy array by computing $1/\mathbf x$ for an array $\mathbf x$.
Compare what happens when you divide by zero using numpy arrays versus using plain floats.
Create a sinusoudal vector [0,1,0,1,... ] of length 100 using numpy. (hint: you can use the modulus operator on arrays)
Show that numpy arrays are copied by reference (i.e., $\mathbf x =\mathbf y$ creates an alias not a new copy) by creating a test example.
Show that the use of .copy() creates a copy properly.
Create a $3\times 3$ array of all ones by creating a nested list then converting it to a numpy array.
Create a $3\times 3$ array of all ones using numpy's ones() function
Create a mask using a numpy array of bool values which can select the diagonal elements from the previous array.
Extract the diagonal values from your matrix using numpy's diag() function instead.
Demonstrate the creation of a diagonal matrix with diagonal values [1,2,3,4] using numpy's diag() function.
Generate a $4 \times 4$ matrix of random values and demonstrate the use of slicing to extract
Create a $3 \times 3$ matrix with random values between -1 and +1
Create a $3 \times 3$ matrix with values which are randomly 1 or zero.
Demonstrate all three ways to transpose your matrix.
Compute the following matrix-vector product using numpy
$\begin{bmatrix} 2 & -6 \\ -1 & 4\\ \end{bmatrix} \begin{bmatrix} 2 \\ -1 \\ \end{bmatrix} = ?$
Use a broadcast product for the above, and explain the result
Compute the following matrix-vector product using numpy
$ \begin{bmatrix} 2 -1 \end{bmatrix} \begin{bmatrix} 2 & -6 \\ -1 & 4\\ \end{bmatrix} = ?$
Use a broadcast product for the above, and explain the result
Create the following matrix using numpy
$\begin{bmatrix} 1 & -1 & 1 \\ 2 & -2 & 2 \\ 3 & -3 & 3 \\ \end{bmatrix} $
The above is a special case where $@$ agrees with $*$
Demonstrate the following matrix-matrix multiplication is accurate by testing it with numpy
$\begin{bmatrix} 1 & 2 \\ 0 & -3 \\ 3 & 1 \\ \end{bmatrix} \begin{bmatrix} 2 & 6 & -3 \\ 1 & 4 & 0 \\ \end{bmatrix} = \begin{bmatrix} 4 & 14 & -3\\ -3 & -12 & 0 \\ 7 & 22 & -9\\ \end{bmatrix}$
what happens if you use $*$ for the above product?
Use the above matrices to test the identity $(\mathbf{A}\mathbf{B})^{T} = \mathbf{B}^{T}\mathbf{A}^{T}$.
Create a $10 \times 5$ random matrix and compute the sum over columns in a single instruction using numpy's sum() function.
Compute the sum over rows instead
Compute the mean and standard deviation over columns using numpy's mean() and std() functions.
Use broadcasting and your mean and std over columns to standardize the columns of your random matrix.
Provide a succinct one-line computation for the sample covariance matrix (assuming the columns of your $10 \times 5$ random matrix are measurements of variables). Hint: use broadcasting to subtract the means, then $\mathbf X^T \mathbf X$ to compute the sum over pairwise products.