Numpy: Exact Filenames Not Allowed
Numpy: Exact Filenames Not Allowed
2024, 11:30 am
NumPy
Solve the following exercises and upload your solutions to Moodle until the specified due date. Make
sure to use the exact filenames that are specified for each individual exercise. Unless explicitly stated
otherwise, you can assume correct user input and correct arguments. You are not allowed to use
any concepts and modules that have not yet been presented in the lecture.
Important Information!
We are running automated tests to aid in the correction and grading process, and deviations
from the expected outputs lead to a significant organizational overhead, which we cannot
handle in the majority of the cases due to the high number of submissions.
1. Please try to exactly match the output given in the examples (naturally, the input can be
different). Feel free to copy the output text from the assignment sheet, and then change it
according to the exercise task.
2. Furthermore, please don’t have any lines of code that will be automatically executed
when importing your module (except for what is asked by the exercise) as this will break our
automated tests. Always execute your module before submitting to verify this !
For example, if you have some code to test your program and reproduce the example outputs,
either comment/remove these lines or move them to the "if __name__ == "main":" section.
1
Programming in Python I Assignment 10 – Due: 24.01.2024, 11:30 am
2
Programming in Python I Assignment 10 – Due: 24.01.2024, 11:30 am
m2 = np.arange(2*3,dtype=float).reshape(2,-1)
print(m2) [[0. 1. 2.]
[3. 4. 5.]]
try:
print(extend(m2, 4,4, fill="foo"))
except ValueError as e:
print(f"ValueError: {e}") ValueError: invalid fill
m3 = np.ones(1)
print(m3) [1.]
try:
print(extend(m3, 2, 3))
except ValueError as e:
print(f"ValueError: {e}") ValueError: can only extend 2D arrays, not 1D
a
Empty lines are shown here just for clarity.
3
Programming in Python I Assignment 10 – Due: 24.01.2024, 11:30 am
Example output:
a1:
[[[ 2. 6. 12.]
[ 20. 30. 42.]]
a2:
[[ 2. 6. 12.]
[20. 30. 42.]]
4
Programming in Python I Assignment 10 – Due: 24.01.2024, 11:30 am
Example output:
[[1. 0. 0.]
[1. 0. 0.]
[0. 1. 0.]
[0. 0. 1.]]
[[0. 1. 0. 0.]
[1. 0. 0. 0.]
[0. 0. 1. 0.]
[0. 0. 0. 1.]]
5
Programming in Python I Assignment 10 – Due: 24.01.2024, 11:30 am
try:
moving_average_2D(np.array([["a", "b"], ["c", "d"]]), 2)
except TypeError as e:
print(f"TypeError: {e}") TypeError: Invalid data type
a
Empty lines are shown here just for clarity.