Exercise 4

Numpy Quest

The Quest

First create a new python file called npquest.py . Within the file, please create the four functions below:

  1. Write a function null_vector(size: int) → np.ndarray which returns a null vector of size size . Recall that a null vector is a vector with all elements of zero.
  2. Write a function transpose(matrix: np.ndarray) → np.ndarray that accepts any numpy array and returns its transpose
  3. Write a function change_zeros(matrix: np.ndarray, value: int) → np.ndarray that accepts any numpy array and returns a new array with all its zeros replaced with value .
  4. Write a function rand_matrix(size: tuple, seed: int = None) -> np.ndarray which returns a matrix with dimensions size and randomized integer values between [1, 255]. If seed is provided, please use it to generate the random matrix.

When you are done, make sure the check_numpy.py file is in the same directory and run uv run check_numpy.py to decode the included secret word file!

Submit the answer: