- 1.What does a neuron compute?
A. A neuron computes the mean of all features before applying the output to an activation function.
B. A neuron computes a linear function (z = Wx + b) followed by an activation function.
C. A neuron computes an activation function followed by a linear function (z = Wx + b).
D. A neuron computes a function g that scales the input x linearly (Wx + b) .
答案:B
一个神经元为计算一个线性函数,并紧跟着一个激活函数(Sigmoid或ReLu)
激活函数是用来加入非线性因素的,因为线性模型的表达能力不够。例如:tanh, sigmoid
- 2.Which of these is the “Logistic Loss”?
A. L(i)(y^(i),y(i)) =−(y(i)log(y(i))+(1−y(i))log(1−y(i)))
B. L(i)(y(i),y(i))=max(0,y(i)−y(i))
C. L(i)(y(i),y(i))=∣y(i)−y(i)∣2
D. L(i)(y(i),y(i))=∣y(i)−y(i)∣
答案:A
解析:
logistic损失函数为交叉熵损失,而不是平方差(会导致非凸求解)
接!
- 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?
A. x = img.reshape((3232,3))
B. x = img.reshape((3,3232))
C. x = img.reshape((32323,1))
D. x = img.reshape((1,32*32,*3))
答案:D
- 4.Consider the two following random arrays “a” and “b”:
a = np.random.randn(2, 3) # a.shape = (2, 3)
b = np.random.randn(2, 1) # b.shape = (2, 1)
c = a + b
What will be the shape of “c”?
A. The computation cannot happen because the sizes don’t match. It’s going to be “Error”!
B. c.shape = (3, 2)
C. c.shape = (2, 3)
D. c.shape = (2, 1)
答案:C
python广播规则,自动填充为(m*n)
- 5.Consider the two following random arrays “a” and “b”:
a = np.random.randn(4, 3) # a.shape = (4, 3)
b = np.random.randn(3, 2) # b.shape = (3, 2)
c = a*b
What will be the shape of “c”?
A. c.shape = (3, 3)
B. c.shape = (4,2)
C. The computation cannot happen because the sizes don’t match. It’s going to be “Error”!
D. c.shape = (4, 3)
答案:C
第一种情况:
a = np.random.randn(4,3)
b = np.random.randn(1,3)
c = a*b
第二种情况:
a = np.random.randn(4,3)
b = np.random.randn(4,1)
c = a*b
这两种情况 采用python的广播机制,有的时候内标不同但是可以使用python广播机制,但是有些会报错。
a = np.random.randn(4,3)
b = np.random.randn(3,6)
c = a.dot(b)
这内标必须一致,不然报错。
∗如果连接两个矩阵的话,那么表示这两个矩阵要同大小,然后是对位点积。否则就要引发广播,而这个矩阵大小不相容,因此引发错误。而如果是numpy.dot的话,则是按照矩阵乘法规则算的。
因此这里是按照对位点积的形式,必须保证两个矩阵相同。否则会报错。
自己试试!!!
- 6.Suppose you have nx input features per example. Recall that X=[x(1)x(2)…x(m)]. What is the dimension of X?
A. (m,1)
B. (1,m)
C. (m,nx)
D. (nx,m)
答案:D
- 7.Recall that “np.dot(a,b)” performs a matrix multiplication on a and b, whereas “a*b” performs an element-wise multiplication.
Consider the two following random arrays “a” and “b”:
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)
What is the shape of c?
A. The computation cannot happen because the sizes don’t match. It’s going to be “Error”!
B. c.shape = (12288, 45)
C. c.shape = (12288, 150)
D. c.shape = (150,150)
答案:numpy.dot对应叉乘,普通的*对应点乘
- 8.Consider the following code snippet:
# a.shape = (3,4)
# b.shape = (4,1)
for i in range(3):
for j in range(4):
c[i][j] = a[i][j] + b[j]
How do you vectorize this?
A. c = a + b.T
B. c = a.T + b.T
C. c = a.T + b
D. c = a + b
答案:A
- 9.Consider the following code:
a = np.random.randn(3, 3)
b = np.random.randn(3, 1)
c = a*b
What will be c? (If you’re not sure, feel free to run this in python to find out).
A. This will invoke broadcasting, so b is copied three times to become (3,3), and ∗ is an element-wise product so c.shape will be (3, 3)
B. This will invoke broadcasting, so b is copied three times to become (3, 3), and ∗ invokes a matrix multiplication operation of two 3x3 matrices so c.shape will be (3, 3)
C. This will multiply a 3x3 matrix a with a 3x1 vector, thus resulting in a 3x1 vector. That is, c.shape = (3,1).
D. It will lead to an error since you cannot use “*” to operate on these two matrices. You need to instead use np.dot(a,b)
答案:A
解析:此处的两个矩阵实相容的,因此会引发广播。而*指的是对位点积。
- 10.Consider the following computation graph.
What is the output J?
A. J = (c - 1)(b + a)
B. J = (a - 1) (b + c)
C. J = ab + bc + a*c
D. J = (b - 1) * (c + a)
答案:B