Last active
February 11, 2018 10:55
-
-
Save iphysresearch/4f0006723cf186195e5685c74408e398 to your computer and use it in GitHub Desktop.
test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def affine_forward(x, w, b): | |
""" | |
Inputs: | |
- x: A numpy array containing input data, of shape (N, d_1, ..., d_k) 样本 | |
- w: A numpy array of weights, of shape (D, M) 权重 | |
- b: A numpy array of biases, of shape (M,) 偏置 | |
Returns a tuple of: | |
- out: output, of shape (N, M) | |
- cache: (x, w, b) | |
""" | |
out = None # 初始化 | |
reshaped_x = np.reshape(x, (x.shape[0],-1)) # 确保x是一个规整的矩阵 | |
out = reshape_x.dot(w) +b # out = w x +b | |
cache = (x, w, b) | |
# cache将该函数的输入值缓冲储存起来,以备后面计算梯度时使用 | |
return out, cache |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment