使用numpy实现一个前向传播的神经网络(不带反向传导功能,未实现)
代码:
import numpy as np
import matplotlib.pyplot as plt
class Net():
def __init__(self):
self.w = np.random.randn(784, 10)
self.b = np.random.randn(10)
def forward(self, x):
x = x.reshape(-1, 784)
y = x @ self.w + self.b
# relu
return np.where(y>0, y, 0)
# nn.relu(nn.Lineaer(784, 10))(X)
image = np.random.randn(28, 28)
print(image)
print(image.shape)
plt.imshow(image, cmap='gray')
plt.imsave("image_1015.png", image, cmap='gray')
net = Net()
y_hat = net.forward(image)
随机生成的图片:

本博客是博主个人学习时的一些记录,不保证是为原创,个别文章加入了转载的源地址,还有个别文章是汇总网上多份资料所成,在这之中也必有疏漏未加标注处,如有侵权请与博主联系。
如果未特殊标注则为原创,遵循 CC 4.0 BY-SA 版权协议。
posted on 2025-10-28 11:36 Angry_Panda 阅读(1) 评论(0) 收藏 举报
浙公网安备 33010602011771号