【发布时间】:2019-05-05 09:14:29
【问题描述】:
我正在向神经网络介绍自己,这是我第一次尝试编写神经网络。希望你能帮帮我:
假设我想编写一个通用的 MLP,这意味着我可以随时更改其自身的 layers_size。 例如,layers_size = [2,2,1] 或 layers_size = [5,40,40,3] [...,...,...]。
我的问题是我不知道如何将每个神经元的随机生成权重保存到二维矩阵中。有人能帮帮我吗?
我正在尝试这样的事情:
weights = []
length = len(layers_size)
#appreciate loop starting in 1 since you dont need
#weights #in the entry layer
#runs layers_size times - 1
for i in range(1, length):
#Gives the amount of neurons for each layer
for j in range(0, layers_size[i]):
#Get the amount of neurons from the previous layer to
# the actual neuron so it saves layers_size[i] - 1
# numWeights for the actual neuron...
weights[i][j] = random...
但我觉得这不是保存 MLP 权重的最佳方法,也不适合我。
你们能帮帮我吗?
感谢您的建议。
PS:tensorflow和keras都不能用。
【问题讨论】:
-
使用 numpy 保存矩阵可以节省时间
标签: python python-3.x neural-network conv-neural-network