起因
在复现吴恩达机器学习代码的过程中,在公式等表达含义无错误的情况下,验证的结果一直未达到理想值。飘啊飘,没错本小白找了一下午才意识到我忽略了矩阵减法中的法则
矩阵减法
#探究(n,)和(n,1)与矩阵相乘的区别
xtry=np.array([[1,0.5],[1,1],[1,2]])
ytry= np.array([[1],[2],[3]])
ytry1 = np.array([[1,2],[2,3],[3,4]])
print(xtry.shape)
print(ytry.shape)
t1 = np.ones(xtry.shape[1])
t2 = np.ones((xtry.shape[1],1))
a1 = xtry@t1
a2 = xtry@t2
print(a1.shape)
print(a2.shape)
print(a1-ytry)
print(a2-ytry)
#print(ytry1-a1)
a3 = (a1-ytry)*(a1-ytry)
a4 = (a2-ytry)*(a2-ytry)
print(a3)
print(a4)