第二周:神经网络基础

第 14 题

考虑以下两个随机数组ab

a = np.random.randn(2, 3) # a.shape = (2, 3)
b = np.random.randn(2, 1) # b.shape = (2, 1)
c = a + b

c的维度是什么?

答: b(列向量)复制3次,以便它可以和a的每一列相加,所以:c.shape = (2, 3)

第 15 题

考虑以下两个随机数组ab

a = np.random.randn(4, 3) # a.shape = (4, 3)
b = np.random.randn(3, 2) # b.shape = (3, 2)
c = a * b

c的维度是什么?

答:运算符 “*” 说明了按元素乘法来相乘,但是元素乘法需要两个矩阵之间的维数相同,所以这将报错,无法计算

第 17 题

np.dot(a,b)对a和b的进行矩阵乘法,而a*b执行元素的乘法,考虑以下两个随机数组ab

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)

c的维度是什么?

答: c.shape = (12288, 45), 这是一个简单的矩阵乘法例子

注:15题和17题的区别如下:

矩阵乘法和数组乘法:

引用:https://blog.csdn.net/weixin_40040404/article/details/81226560

第 19 题

请考虑以下代码段:

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

c的维度是什么?

A.这会触发广播机制,b会被复制3次变成(3*3),而*操作是元素乘法,所以c.shape = (3, 3)【a,b矩阵的维度相同】

原文地址:https://www.cnblogs.com/spore/p/13022515.html