import numpy as np
a1 = -0.9
a2 = 0.5
a3 = 0.7
input1 = np.array([a1, a2, a3])
input1 = np.array([[a1, a2, a3],
[-a1, -a2, -a3]])
w11 = 0.8
w21 = -0.4
w31 = 0
w12 = 0.5
w22 = -0.2
w32 = 0
weights = np.array([[w11, w12],
[w21, w22],
[w31, w32]])
# weights = np.array([w1,
# w2,
# w3])
b1 = np.array([-100, 100])
# sum1 = a1*w1 + a2*w2 + a3*w3 + b1
# sum1 = np.dot(input1, weights) + b1
# 激活函数
def activation_relu(input):
return np.maximum(0, input)
# 权重生成函数
def create_weights(n_inputs, n_neurons):
return np.random.randn(n_inputs, n_neurons)
# 偏置生成函数
def create_bias(n_neurons):
return np.random.randn(n_neurons)
weights = create_weights(3, 2)
bias = create_bias(2)
print(bias)
sum0 = np.dot(input1, weights)
sum1 = np.dot(input1, weights) + bias
sum2 = activation_relu(sum1)
print(sum0)
print(sum1)
print(sum2)
02_函数生成权重矩阵
最新推荐文章于 2024-07-12 16:16:27 发布