Question 1Easy
What does this code print?
import numpy as np
a = np.array([[1, 2, 3], [4, 5, 6]])
print(a.shape)- (2,)
- 6
- (3, 2)
- (2, 3)
Answer: D. (2, 3)
Explanation
The array has 2 rows and 3 columns; shape is a (rows, columns) tuple.
Step-by-step solution
- The array has 2 inner lists (rows).
- Each row has 3 elements (columns).
- shape = (rows, columns) = (2, 3).
Why the other options are wrong
- A. (2,) would be a 1-D array of two elements.
- B. 6 is a.size, not the shape.
- C. (3, 2) swaps rows and columns.