def conv_single_step(a_slice_prev, W, b):
"""
Apply one filter defined by parameters W on a single slice (a_slice_prev) of the output activation
of the previous layer.
Arguments:
a_slice_prev -- slice of input data of shape (f, f, n_C_prev)
W -- Weight parameters contained in a window - matrix of shape (f, f, n_C_prev)
b -- Bias parameters contained in a window - matrix of shape (1, 1, 1)
Returns:
Z -- a scalar value, result of convolving the sliding window (W, b) on a slice x of the input data
"""
# Element-wise product between a_slice and W. Add bias.
assert(a_slice_prev.shape == W.shape)
s = W * a_slice_prev + b
# Sum over all entries of the volume s
Z = np.sum(s)
return Z
np.random.seed(1)
a_slice_prev = np.random.randn(4, 4, 3) # height * width * channel
W = np.random.randn(4, 4, 3)
b = np.random.randn(1, 1, 1)
Z = conv_single_step(a_slice_prev, W, b)
print("Z =", Z)
assert '{:.2f}'.format(Z) == '-23.16'