【发布时间】:2019-08-26 23:18:53
【问题描述】:
我正在 ipython 脚本下使用 python3.7 在我的 anaconda 中尝试神经网络前馈。
我不熟悉,还在学习python的问题,不知道如何调试。
import numpy as np
w1 = np.array([[11, 11, 9, 11, 7,13, 14, 6, 6, 12], [11, 11, 9, 11, 7,13, 14, 6, 6, 12], [11, 11, 9, 11, 7,13, 14, 6, 6, 12]])
w2 = np.zeros ((1,10))
b1 = np.array([0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8])
b2 = np.array([0.2])
def f(x):
return 1 / (1 + np.exp(-x))
def simple_looped_nn_calc(n_layers, x,w,b):
for l in range(n_layers-1):
if l == 0:
node_in = x
else:
node_in = h
h = np.zeros((w[l].shape[0],))
for i in range(w[l].shape[0]):
f_sum = 0
for j in range(w[l].shape[l]):
f_sum += w[l][i][j]* node_in[j]
f_sum += b[l][i]
h[i] = f(f_sum)
return h
w = [w1, w2]
b = [b1, b2]
x = [280, 0, 280, 280, 0, 0, 0, 0, 280, 0, 0, 0, 0, 0, 0, 0, 0, 280, 0]
当我运行我的代码时,我得到了错误,simple_looped_nn_calc(3, x, w, b) 像这样:
IndexError:索引 3 超出轴 0 的范围,大小为 3
【问题讨论】:
-
知道错误出现在哪一行会有所帮助!
标签: python arrays numpy ipython python-3.7