Array Properties
Problem Statement
Examine and report properties of a NumPy array.
Background
NumPy arrays have useful properties:
- shape: Tuple of dimensions
- dtype: Data type
- size: Total number of elements
- ndim: Number of dimensions
Your Task
Write a function array_info(arr) that returns information about an array.
Output Format
Return a dictionary with:
- "shape": Tuple of dimensions (as list)
- "dtype": Data type as string
- "size": Total elements
- "ndim": Number of dimensions
- "is_matrix": True if 2D, False otherwise
Example
np.array([[1, 2, 3], [4, 5, 6]])
{'shape': [2, 3], 'dtype': 'int64', 'size': 6, 'ndim': 2, 'is_matrix': True}- Input: the nested list
[[1, 2, 3], [4, 5, 6]]is a grid of whole numbers with 2 rows, each holding 3 entries — a array of integers. shape: the length along each axis, outermost first: 2 rows, then 3 columns, giving[2, 3]. It is reported as a list, not a tuple.ndim: the number of axes, which is just how many entriesshapehas — here 2.size: the total count of elements, the product of the axis lengths: .dtype: every entry is an integer, so the element type is a 64-bit integer, reported as the text'int64'(some systems report a 32-bit integer instead; both are accepted).is_matrix:Trueexactly when there are 2 axes. Notice that a flat list of 5 numbers has one axis and givesFalse, and so does a block, even though both still have asize( and ).
Constraints
- dtype output may vary by system (int64, int32, float64, etc.)
- Accept both int64 and int32 as valid integer dtypes