File tree Expand file tree Collapse file tree 4 files changed +25
-7
lines changed Expand file tree Collapse file tree 4 files changed +25
-7
lines changed Original file line number Diff line number Diff line change 11import numpy as np
2- from tasks import step , ReLU
2+ from tasks import step , ReLu # wrong name call ~ ReLU
33
44
55def test_relu_default_cutoff ():
Original file line number Diff line number Diff line change 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# ------------------------------------------
You can’t perform that action at this time.
0 commit comments