Lab 3

Download the ipynb file numpy-I.ipynb.

NumPy Basics

Note Exercise 1

Create a NumPy 1D array or vector with only even numbers between 12 to 124.

Note Exercise 2

Print the shape, length, and data type of the array created in Ex 1.

Note Exercise 3

Create a NumPy 1D array or vector with only odd numbers between 12 to 124 in decreasing order.

Note Exercise 4

Modify the array create in Ex 1 so that its 15th element becomes 6103.

Note Exercise 5

Create a 2\times5 matrix filled with numbers between 102 and 129 that are divisible by 3.

Note Exercise 6

Create a NumPy array A of shape (3, 4, 4) such that each of the slices along the first axis (axis=0) is an identity matrix.

Note Exercise 7

Create a NumPy array A of shape (3, 3, 5) such that the last axis (column) of each of the slices along the first axis is [6101, 6102, 6103].

Note Exercise 8

What is the result (True or False) of each of the following expressions? Justify your answer.

0 * np.nan # (8.1)
np.nan == np.nan # (8.2)
np.inf > np.nan # (8.3)
np.nan - np.nan # (8.4)
np.nan in set([np.nan]) # (8.5)
0.3 == 3 * 0.1 # (8.6)
Note Exercise 9

Check if a given matrix is symmetric.

Note Exercise 10

Check if a given matrix is skew-symmetric.

Note Exercise 11

Check if a given matrix is diagonal.

Note Exercise 12

Check if a matrix is orthogonal.

Note Exercise 13

Create a 6\times6 matrix with values 1, 2, 3, 4, 5 just above the diagonal and -3 everywhere else.