【深度学习吴恩达】神经网络和深度学习--第二周课后测验及编程作业

测验题

5 . Consider the two following random arrays “a” and “b”:(看一下下面的这两个随机数组“a”和“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”?(请问数组“c”的维度是多少? )

Answer:
The computation cannot happen because the sizes don’t match. It’s going to be “error”!

Note:“*” operator indicates element-wise multiplication. Element-wise multiplication requires same
dimension between two matrices. It’s going to be an error.(注: 运算符 “ * ” 说明了按元素乘法来相乘,但是元素乘法需要两个矩阵之间的维数相同,所以这将报错,无法计算。 )

7 . Recall that np.dot(a,b) performs a matrix multiplication on a and b, whereas a*b performs an element-wise multiplication.(回想一下, np.dot(a, b) 在 a 和 b 上执行矩阵乘法,而“a*b”执行元素方式的乘法。 )Consider the two following random arrays “a” and “b”:(看一下下面的这两个随机数组“a”和“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?(请问 c 的维度是多少? )

Answer:
c.shape = (12288, 45), this is a simple matrix multiplication example.( c.shape = (12288, 45), 这是一个简单的矩阵乘法例子。 )

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?(请问要怎么把它们向量化? )

Answer:

c = a + b.T

【注】注意此处需要看懂题目中代码的含义,再配合转置即可回答问题。

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 的维度会是多少? )

Answer:
c.shape = (3, 3)

This will invoke broadcasting, so b is copied three times to become (3,3), and * is an elementwise product so c.shape = (3, 3).(这将会使用广播机制, b 会被复制三次,就会变成(3,3),再使用元素乘法。所以: c.shape = (3, 3).)

【注】总结 5、7、9 题,可以看出,ab 和 dot(a,b) 的计算方式是不一样的,ab 要求 a 和 b 的矩阵维度至少有一个是一样的,或者其中一个矩阵的维度为1才能利用广播机制正确返回元素相乘结果;而 dot(a,b) 对两个矩阵的维度的要求是符合矩阵相乘的要求就行,即为前面的矩阵的列数和后面矩阵的行数一样即可。

编程题

1、吴恩达老师英文题目下载链接(个人觉得阅读一下吴老师原题目也是有帮助的)

链接:https://pan.baidu.com/s/129etFGse1yCqx9mWczHQVg
提取码:h518

2、相关编程素材(数据集,py 文件等)下载链接 https://github.com/EvanMi/angleDeepLearning/tree/master/angle_01_week_02

3、何宽中文解释博客地址(在翻译吴老师英文的基础上添加了一些改动) https://blog.csdn.net/u013733326/article/details/79639509

总结

自己跟着博主何宽的教程搭建了一个简单的神经网络,一点一点地理解每个函数以及每个参数的意义,感觉自己对神经网络理解的更深入了一点。希望自己以后能独立搭建出神经网络,加油~

在理解代码时参考了以下两篇博客:
1. matplotlib笔记——legend用法
2. plt.plot(),plt.scatter(),plt.legend函数的用法介绍

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

早知晓

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值