吴恩达深度学习作业L1W2:ValueError: cannot reshape array of size 12288 into shape (50,1)

照着代码敲下来,测试部分的代码都没问题,到了最后整合的实战代码就突然报错ValueError: cannot reshape array of size 12288 into shape (50,1),跳转过来显示model函数以下部分:

Y_prediction_test=predict(w,b, X_test)

原因为测试集没有进行转置操作,格式仍为(50,12288),进行转置即可,即修改为:

Y_prediction_test=predict(w,b, X_test.T)

便可正常运行了,结果也和预期输出一致:

.......

Cost after iteration 1600:0.159305
Cost after iteration 1700:0.152667
Cost after iteration 1800:0.146542
Cost after iteration 1900:0.140872
train accuracy: 99.04306220095694 %
test accuracy: 70.0 %

你可能感兴趣的:(吴恩达深度学习作业L1W2:ValueError: cannot reshape array of size 12288 into shape (50,1))