1.What does a neuron compute?
- []A neuron computes an activation function followed by a linear function \(z = w^Tx + b\)
- [√]A neuron computes a linear function \(z = w^Tx + b\) followed by an activation function
- []A neuron computes a function g that scales the input \(x\) linearly \(w^Tx + b\)
- []A neuron computes the mean of all features before applying the output to an activation function
Note: The output of a neuron is \(a = g(w^Tx + b)\) where g is the activation function (sigmoid, tanh, ReLU, …).
2.Which of these is the “Logistic Loss”?
pass
3.Suppose img is a (32,32,3) array, representing a 32x32 image with 3 color channels red, green and blue. How do you reshape this into a column vector?
x.img.reshape((32 * 32 * 3), 1)
4.Consider the two following random arrays “a” and “b”:What will be the shape of “c”?
import numpy as np
a = np.random.randn(2, 3)
b = np.random.randn(2, 1)
c = a + b
print("The shape of c is " + str(c.shape))
The shape of c is (2, 3)
5.Consider the two following random arrays “a” and “b”:What will be the shape of “c”?
a = np.random.randn(4, 3) # a.shape = (4, 3)
b = np.random.randn(3, 2) # b.shape = (3, 2)
c = a * b
"*" operator indicates element-wise multiplication. Element-wise multiplication requires same dimension between two matrices. It’s going to be an error.
6.Suppose you have \(n_x\) input features per example. Recall that \(X = [x^{(1)}, x^{(2)}…x^{(m)}]\). What is the dimension of X?
answer:\((n_x, m)\)
7.Recall that np.dot(a,b)
performs a matrix multiplication on a and b, whereas a * b
performs an element-wise multiplication.What is the shape of c?
import numpy as np
a = np.random.randn(12288, 150) # a.shape = (12288, 150)
b = np.random.randn(150, 45) # b.shape = (150, 45)
c = np.dot(a, b)
print("The shape of c is " + str(c.shape))
The shape of c is (12288, 45)
8.Consider the following code snippet,How do you vectorize this?
import numpy as np
a = np.random.randn(3, 4)
b = np.random.randn(4, 1)
c = np.zeros((3, 4))
for i in range(3):
for j in range(4):
c[i][j] = a[i][j] + b[j]
print(c)
# vectorization
c = a + b.T
print(c)
[[-0.06128172 1.38358218 -1.67582622 -0.84986718]
[ 0.56135718 2.25381567 -1.68680999 0.01224835]
[-0.07907139 1.80305704 -3.07796686 -0.74300536]]
[[-0.06128172 1.38358218 -1.67582622 -0.84986718]
[ 0.56135718 2.25381567 -1.68680999 0.01224835]
[-0.07907139 1.80305704 -3.07796686 -0.74300536]]
9.Consider the following code, What will be c?
import numpy as np
a = np.random.randn(3, 3)
b = np.random.randn(3, 1)
c = a * b
print(c.shape)
(3, 3)
This will invoke broadcasting, so b is copied three times to become (3,3)