v9.1.1
Menu

Array Properties

easyFREEArray Creation & BasicsNumPy ArraysNumPy Foundations

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

Input
np.array([[1, 2, 3], [4, 5, 6]])
Output
{'shape': [2, 3], 'dtype': 'int64', 'size': 6, 'ndim': 2, 'is_matrix': True}
Reasoning
  • Input: the nested list [[1, 2, 3], [4, 5, 6]] is a grid of whole numbers with 2 rows, each holding 3 entries — a 2×32 \times 3 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 entries shape has — here 2.
  • size: the total count of elements, the product of the axis lengths: 2×3=62 \times 3 = 6.
  • 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: True exactly when there are 2 axes. Notice that a flat list of 5 numbers has one axis and gives False, and so does a 2×2×22 \times 2 \times 2 block, even though both still have a size (55 and 88).

Constraints

  • dtype output may vary by system (int64, int32, float64, etc.)
  • Accept both int64 and int32 as valid integer dtypes

More from NumPy Foundations

solution.py

Test results

Sign in to run your code against the test cases.