Skip to content

Commit 0cacc44

Browse files
committed
Completed assignment and added certificate (python only). Fixed import error in grade_task2.
1 parent e9f437b commit 0cacc44

File tree

4 files changed

+25
-7
lines changed

4 files changed

+25
-7
lines changed

__pycache__/tasks.cpython-313.pyc

1.26 KB
Binary file not shown.

certificate.pdf

543 KB
Binary file not shown.

grade_task2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import numpy as np
2-
from tasks import step, ReLU
2+
from tasks import step, ReLu # wrong name call ~ ReLU
33

44

55
def test_relu_default_cutoff():

tasks.py

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@
1313
# Your code here:
1414
# -----------------------------------------------
1515

16-
def step
17-
16+
def step(num):
17+
if num > 0:
18+
return 1
19+
else:
20+
return -1
1821

1922
# -----------------------------------------------
2023

@@ -28,8 +31,10 @@ def step
2831

2932
# Your code here:
3033
# -----------------------------------------------
31-
def ReLu
32-
34+
def ReLu(vector, cutoff=0):
35+
result = vector.copy()
36+
result[result < cutoff] = cutoff
37+
return result
3338

3439
# -----------------------------------------------
3540

@@ -44,7 +49,20 @@ def ReLu
4449
# Your code here:
4550
# -----------------------------------------------
4651

47-
def neural_net_layer
48-
52+
def neural_net_layer(matrix, vector):
53+
if matrix.shape[1] != vector.shape[0]:
54+
raise ValueError("Incompatible shapes for matrix multiplication.")
55+
56+
result = numpy.zeros(matrix.shape[0])
57+
for i in range(matrix.shape[0]):
58+
product = 0
59+
for j in range(matrix.shape[1]):
60+
product += matrix[i][j] * vector[j]
61+
result[i] = product
62+
63+
# or using numpy
64+
# result = numpy.dot(matrix, vector)
65+
66+
return ReLu(result)
4967

5068
# ------------------------------------------

0 commit comments

Comments
 (0)