A developer needs a NumPy array filled entirely with zeros, with shape (3, 4, 5) to use as a placeholder tensor. Which line of code correctly creates it?
Select an answer to reveal the explanation.
Short Explanation and Infographic
np.zeros() takes exactly one required positional argument — the shape — and that shape has to be passed as a single tuple (or list), not as separate arguments. So np.zeros((3, 4, 5)) is correct: the double parentheses aren't a typo, the outer pair is the function call and the inner pair is the shape tuple. np.zeros(3, 4, 5) will blow up because NumPy interprets those as three separate positional arguments (shape, dtype, order) rather than a 3-D shape, and passing 4 where a dtype is expected doesn't work. np.zeros([3][4][5]) is just broken syntax — that's chained indexing into a list literal, not a shape specification. And np.zeros(shape=3+4+5) would just evaluate to np.zeros(shape=12), giving you a 1-D array of 12 zeros, not a (3, 4, 5) three-dimensional array at all.
Full explanation below image
Full Explanation
NumPy's np.zeros() function creates a new array filled with zeros, and its signature is np.zeros(shape, dtype=float, order='C'), where shape must be provided either as a single integer (for a 1-D array) or as a tuple (or list) of integers specifying the size along each dimension for a multi-dimensional array. To create a 3-D array with dimensions 3, 4, and 5, the shape must be passed as the tuple (3, 4, 5), giving np.zeros((3, 4, 5)). This produces an array with 345 = 60 total elements, all initialized to 0.0, correctly organized into the requested three-dimensional structure.
np.zeros(3, 4, 5) is incorrect because it passes 3, 4, and 5 as three separate positional arguments rather than as a single shape tuple. Following the function's actual signature, this would be interpreted as shape=3, dtype=4, order=5, which is nonsensical (4 is not a valid dtype) and will raise an error rather than creating the intended 3-D array. This is one of the most common syntax mistakes among developers coming from languages where multi-dimensional array constructors take dimensions as separate arguments.
np.zeros([3][4][5]) is invalid Python syntax in this context. [3] creates a one-element list containing 3, and then [4] attempts to index into that list at position 4, which is out of bounds and would raise an IndexError before np.zeros is even meaningfully called with a valid shape; this expression does not represent a 3-D shape specification at all.
np.zeros(shape=3+4+5) evaluates the expression 3+4+5 first, which equals 12, so this call is equivalent to np.zeros(shape=12) or np.zeros(12), producing a flat 1-D array containing 12 zero elements — not a 3-D array with the intended (3, 4, 5) shape. This illustrates why the individual dimension sizes must be grouped together as a tuple, not combined arithmetically.
The key takeaway is that NumPy shape parameters for multi-dimensional arrays are always specified as a single sequence (tuple or list) argument, a convention shared across many NumPy and deep learning framework functions such as np.ones(), np.random.rand(), and torch.zeros(), so recognizing and correctly using the tuple-shape pattern is a fundamental skill for working with tensors.