当前位置: 代码迷 >> 综合 >> 吴恩达 deeplearning.ai - 神经网络和深度学习 - 第二周测验
  详细解决方案

吴恩达 deeplearning.ai - 神经网络和深度学习 - 第二周测验

热度:40   发布时间:2023-11-11 06:52:47.0

原文链接:https://blog.csdn.net/u013733326/article/details/79862336

Week 2 Quiz - Neural Network Basics

1.What does a neuron compute?

  1. A neuron computes an activation function followed by a linear function (z = Wx + b)
  2. A neuron computes a linear function (z = Wx + b) followed by an activation function
  3. A neuron computes a function g that scales the input x linearly (Wx + b)
  4. A neuron computes the mean of all features before applying the output to an activation function

解:2

神经元绩点先计算线性函数的结果z,然后在计算激活函数的值a。其中a=g(z),g是激活函数(sigmoid,tanh,ReLU……)。

2.Which of these is the “Logistic Loss”?

解:我们使用交叉熵损失函数。

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))

列向量是(n, 1)的向量,使用reshape函数来更改元素位置。

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和b的形状不同,会触发广播机制,b将元素进行复制到(2, 3),c的形状为(2, 3)

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”?

解:“*”运算符用于按元素乘法来相乘,但是元素乘法需要两个矩阵之间的,所以这将报错,无法计算。

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?

解:(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.

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?

解:(12288, 45), (m, n)的矩阵与(n, l)的矩阵相乘,结果为(m, l)的矩阵

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?

解:c = a + b.T

可以看出,c每行的元素等于a每行的元素加上一个相同的元素b对应的元素。所以应该是广播的用法。

9.Consider the following code:

a = np.random.randn(3, 3)
b = np.random.randn(3, 1)
c = a * b

What will be c?

解:仍然是广播机制,所以c的形状是(3, 3)。

10.Consider the following computation graph.

J = u + v - w= a * b + a * c - (b + c)= a * (b + c) - (b + c)= (a - 1) * (b + c)

解:(a - 1) * (b + c)

  相关解决方案