In [1]:
import numpy as np

In [2]:
a = np.zeros((4, 3), dtype=np.int)
print(a)


[[0 0 0]
 [0 0 0]
 [0 0 0]
 [0 0 0]]

In [3]:
print(a.shape)


(4, 3)

In [4]:
b = np.arange(6).reshape(2, 3)
print(b)


[[0 1 2]
 [3 4 5]]

In [5]:
print(b.shape)


(2, 3)

In [6]:
# print(a + b)
# ValueError: operands could not be broadcast together with shapes (4,3) (2,3)

In [7]:
a = np.zeros((2, 3, 4), dtype=np.int)
print(a)


[[[0 0 0 0]
  [0 0 0 0]
  [0 0 0 0]]

 [[0 0 0 0]
  [0 0 0 0]
  [0 0 0 0]]]

In [8]:
print(a.shape)


(2, 3, 4)

In [9]:
b = np.arange(3)
print(b)


[0 1 2]

In [10]:
print(b.shape)


(3,)

In [11]:
# print(a + b)
# ValueError: operands could not be broadcast together with shapes (2,3,4) (3,)

In [12]:
b_3_1 = b.reshape(3, 1)
print(b_3_1)


[[0]
 [1]
 [2]]

In [13]:
print(b_3_1.shape)


(3, 1)

In [14]:
print(a + b_3_1)


[[[0 0 0 0]
  [1 1 1 1]
  [2 2 2 2]]

 [[0 0 0 0]
  [1 1 1 1]
  [2 2 2 2]]]