私は簡単なディープラーニングのプログラムを作ろうと思っています。
しかし、numpyでの行列計算ができません。
printで出力している通り、11と13の計算なので出来るはずです。
なぜ計算ができないのでしょうか?
python
1%matplotlib inline 2 3import numpy as np 4import matplotlib.pyplot as plt 5 6INPUT_DATA = np.arange(0,np.pi*2,0.1) 7CORRECT_DATA = np.sin(INPUT_DATA) 8WEIGHT = 0.1 9 10class Layer: 11 def __init__(this,input_num,output_num): 12 this.w = WEIGHT * np.random.randn(input_num,output_num) 13 this.b = WEIGHT * np.random.randn(output_num) 14 15 def forward(this,x): 16 print(x,this.w) 17 this.y = np.dot(x,this.w) 18 print(this.y) 19 20layer = Layer(1,3) 21output = Layer(3,1) 22 23layer.w = np.array([0.1,0.2,0.3]) 24output.w = np.array([0.1]) 25 26plot_x = [] 27plot_y = [] 28 29for i in range(10): 30 layer.forward(np.array([i]).reshape(1)) 31 output.forward(layer.y) 32 33 plot_x.append(i) 34 plot_y.append(layer.y) 35 36print(layer.w,layer.b) 37print(output.w,output.b) 38plt.scatter(plot_x,plot_y,marker="+") 39plt.show()
[0] [0.1 0.2 0.3] --------------------------------------------------------------------------- ValueError Traceback (most recent call last) <ipython-input-3-633891e69ff3> in <module>() 28 29 for i in range(10): ---> 30 layer.forward(np.array([i]).reshape(1)) 31 output.forward(layer.y) 32 <ipython-input-3-633891e69ff3> in forward(this, x) 15 def forward(this,x): 16 print(x,this.w) ---> 17 this.y = np.dot(x,this.w) 18 print(this.y) 19 ValueError: shapes (1,) and (3,) not aligned: 1 (dim 0) != 3 (dim 0)
回答1件
あなたの回答
tips
プレビュー