The code you have provided has an error. The variable "shape" has been used even before declaring it. Replacing it from the current position to the line above "# Understand with for-loops" will rectify the error. Here's the corrected code.
# Answer
y = np.array([2, 3, 4]).reshape(1, 3, 1, 1)
# or
# y = np.array([2, 3, 4]).reshape(3, 1, 1)
shape = (1000, 3, 32, 32)
# Understand with for-loops
x = np.ones(shape, dtype=np.uint8) # for example
out = np.empty(shape, dtype=np.uint8)
N, C, W, H = shape
for n in range(N):
for channel in range(C):
for w in range(W):
for h in range(H):
out[n, channel, w, h] = x[n, channel, w, h] * y[0, channel, 0, 0]
The code you have provided has an error. The variable "shape" has been used even before declaring it. Replacing it from the current position to the line above "# Understand with for-loops" will rectify the error. Here's the corrected code.
Thank you.