# 1.什么是数组广播：

``````x = np.array([[133, 160],
[160, 172],
[152, 70],
[120, 60]])
y = np.array([[1, 0]])
y = y + x``````

``````x = np.array([[133, 160],
[160, 172],
[152, 70],
[120, 60]])
y = np.array([[1, 0],
[1, 0],
[1, 0],
[1, 0]])
y = y + x``````

[[134 160]

[161 172]

[153 70]

[121 60]]

# 2.+=不支持广播特性

``````self.w -= self.d_w * alpha
self.b -= self.d_b * alpha
self.x -= self.d_x * alpha
self.z -= self.d_z * alpha
self.a -= self.d_a * alpha``````

b的维度是1*2，d_b的维度是4*2。

self.b -= self.d_b * alpha

ValueError: non-broadcastable output operand with shape (1,2) doesn't match the broadcast shape (4,2)

• 使用赋值操作符

``````    x = np.array([[133, 160],
[160, 172],
[152, 70],
[120, 60]])
y = np.array([[1, 0]])
y = y + x  # 不报错
print(y)``````

[[134 160]

[161 172]

[153 70]

[121 60]]

• 使用自加操作符：

``````    x = np.array([[133, 160],
[160, 172],
[152, 70],
[120, 60]])
y = np.array([[1, 0]])
y += x  # 报错
print(y)``````

ValueError: non-broadcastable output operand with shape (1,2) doesn't match the broadcast shape (4,2)

THE END