Exercise 4
Numpy Quest
- Fork and clone the repository: https://github.com/ds-grundlagen/numpy-quest
- Clone it to your computer and open it in vs code
- Initialize a new uv environment and add the
numpypackage
The Quest
First create a new python file called npquest.py . Within the file, please create the four functions below:
- Write a function
null_vector(size: int) → np.ndarraywhich returns a null vector of sizesize. Recall that a null vector is a vector with all elements of zero. - Write a function
transpose(matrix: np.ndarray) → np.ndarraythat accepts any numpy array and returns its transpose - Write a function
change_zeros(matrix: np.ndarray, value: int) → np.ndarraythat accepts any numpy array and returns a new array with all its zeros replaced withvalue. - Write a function
rand_matrix(size: tuple, seed: int = None) -> np.ndarraywhich 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!