【发布时间】:2015-05-11 01:58:30
【问题描述】:
我将 Matlab 中的权重和偏差导出到 python 中以用于神经实验室。我的网络有 8 个输入、3 个输入权重数组、4 个分层权重数组和 4 个输出神经元。这是我第一次这样做,我真的需要帮助才能完成它。下面是我的实现和我得到的错误。
import numpy as np
import neurolab as nl
net = nl.net.newff([[0, 1]], [3, 4])
input_w=[[-24.1874,24.1622,0.0755,-0.2521,4.4625,-10.7961,6.2183,0.2680],...]
input_w = np.array(input_w)
input_w = np.reshape(input_w, (8,3))
layer_w=[[-3.7940,-0.0336,-14.9024],......]
layer_w = [np.array(x) for x in (layer_w)]
layer_w = np.reshape(layer_w, (3,4))
input_bias =[0.4747,-1.2475,-1.2470]
bias_2=np.array([-10.9982,1.9692,5.0705,-0.1236])
bias_2 = np.reshape(bias_2, (4))
net.layers[0].np['w'][:] = input_w.
net.layers[1].np['w'][:] = layer_w.
net.layers[1].np['b'][:] = np.array([input_bias])
net.layers[0].np['b'][:] = bias_2
print net.sim([[0.015,0.022,0.0,0.0,0.432,0.647,0.831]])
Traceback (most recent call last):
File "C:\Python27\neural13.py", line 206, in <module>
net.layers[0].np['w'][:] = input_w
ValueError: could not broadcast input array from shape (8,3) into shape (3,1)
感谢您的建议,如果您需要更多信息,请随时询问。
【问题讨论】:
标签: python matlab neural-network