-
Notifications
You must be signed in to change notification settings - Fork 0
/
p4.py
47 lines (33 loc) · 1.09 KB
/
p4.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import numpy as np
# inputs=[[1,2,3,2.5],
# [2.0,5.0,-1.0,2.0],
# [-1.5,2.7,3.3,-0.8]]
# weights=[[0.2,0.8,-0.5,1.0],
# [0.5,-0.91,0.26,-0.5],
# [-0.26,-0.27,0.17,0.87]]
# biases=[2,3,0.5]
# weights2=[[0.1,-0.14,0.5],
# [-0.5,0.12,-0.33],
# [-0.44,0.73,-0.13]]
# biases2=[-1,2,-0.5]
# # output=np.dot(inputs,weights)+biases ''This would throw a shape error, and so will np.dot(weights,inputs)''
# layer1_outputs=np.dot(inputs,np.array(weights).T)+biases
# # print(output)
# layer2_outputs=np.dot(layer1_outputs,np.array(weights2).T)+biases2
# print(layer2_outputs)
np.random.seed(0)
X=[[1,2,3,2.5],
[2.0,5.0,-1.0,2.0],
[-1.5,2.7,3.3,-0.8]]
class Layer_Dense:
def __init__(self,n_inputs,n_neurons):
self.weights=0.10*np.random.randn(n_inputs,n_neurons)
self.biases=np.zeros((1,n_neurons))
def forward(self,inputs):
self.output=np.dot(inputs,self.weights)+self.biases
layer1=Layer_Dense(4,5)
layer2=Layer_Dense(5,2)
layer1.forward(X)
# print(layer1.output)
layer2.forward(layer1.output)
print(layer2.output)