a Neural Network with a single hidden layer (具有单个隐藏层的神经网络)

本文介绍了如何使用NumPy库中的np.dot和np.multiply函数来计算成本,通过np.multiply进行元素级乘法,然后使用np.sum求和,或者直接使用np.dot计算矩阵乘法。文中还提到了结果类型的不同,np.multiply和np.sum组合使用会得到浮点数,而np.dot则返回一个二维数组,可以使用np.squeeze去除冗余维度。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

(you can use either np.multiply() and then np.sum() or directly np.dot()).
Note that if you use np.multiply followed by np.sum the end result will be a type float, whereas if you use np.dot, the result will be a 2D numpy array. We can use np.squeeze() to remove redundant dimensions (in the case of single float, this will be reduced to a zero-dimension array). We can cast the array as a type float using float().

logprobs = np.multiply(np.log(A2),Y)
cost = - np.sum(logprobs)   

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值