다음과 같이 (4, 3) 형태의 배열과 (4,) 형태의 1차원 벡터를 연산하면 열의 크기와 1차원 벡터의 크기가 달라 브로드캐스팅되지 않고 오류가 발생할 수 있으므로 주의해야 한다.
e = np.array([1, 2, 3, 4]) print(c.shape, e.shape) c + e
실행 결과
(4, 3) (4,)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-4-b046b312de3b> in <module>
1 e = np.array([1, 2, 3, 4])
2 print(c.shape, e.shape)
----> 3 c + e
ValueError: operands could not be broadcast together with shapes (4,3) (4,)