#批量处理代码的修改工作主要在批量计算梯度和批量更新权值上
##批量输入后,如何使用numpy矩阵计算的方法计算各权值梯度,提高计算速度
def backprop(self, x, y): #x为多维矩阵。每列为一个x值。 y为多维矩阵。每列为一个y值。
batch_num=x.shape[1]
#print(x.shape)
#print(y.shape)
"""创建两个变量,用来存储所有b值和所有w值对应的梯度值。初始化为0.nabla_b为一个list,形状与biases的形状完全一致。nabla_w 为一个list,形状与weights的形状完全一致。
"""
nabla_b = [np.zeros(b.shape) for b in self.biases]
nabla_w = [np.zeros(w.shape) for w in self.weights]
# feedforward
"""activations,用来所有中间层和输出层在一次前向计算过程中的最终输出值,即a值。该值记录下来,以供后期使用BP算法求每个b和w的梯度。
"""
activation = x #x为本批多个x为列组成的矩阵。
activations = [x] # list to store all the activations, layer by layer
"""zs,用来所有中间层和输出层在一次前向计算过程中的线性输出值,即z值。该值记录下来,以供后期使用BP算法求每个b和w的梯度。
"""
zs = [] # list to store all the z vectors, layer by layer ,zs的每个元素为本batch的x对应的z为列构成的矩阵。
"""
通过一次正向计算,将中间层和输出层所有的z值和a值全部计算出来,并存储起来。供接下来求梯度使用。
"""
for b, w in zip(self.biases, self.weights):
#print(w.shape)
#print(np.dot(w, activation).shape)
#print(b.shape)
z = np