In [1]:
import numpy as np
In [2]:
a = np.zeros((4, 3), dtype=np.int)
print(a)
In [3]:
print(a.shape)
In [4]:
b = np.arange(6).reshape(2, 3)
print(b)
In [5]:
print(b.shape)
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)
In [8]:
print(a.shape)
In [9]:
b = np.arange(3)
print(b)
In [10]:
print(b.shape)
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)
In [13]:
print(b_3_1.shape)
In [14]:
print(a + b_3_1)