PIXELBANKv8.2.1
Menu

Create NumPy Array from List

Problem Statement

Create a NumPy array from a Python list and return its basic properties.

Background

NumPy arrays are the foundation of numerical computing in Python. Unlike Python lists, NumPy arrays are:

  • Homogeneous (all elements same type)
  • More memory efficient
  • Support vectorized operations

Your Task

Write a function create_array(python_list) that:

  1. Converts the input list to a NumPy array
  2. Returns a dictionary with:
    • "array": The array as a list
    • "shape": The shape as a list
    • "dtype": The data type as a string
    • "ndim": Number of dimensions

Output Format

Return a dictionary with exactly these four keys.

Example:

Input:
[1, 2, 3, 4, 5]
Output:
{'array': [1, 2, 3, 4, 5], 'shape': [5], 'dtype': 'int64', 'ndim': 1}
Reasoning:

np.array converts list to ndarray with inferred dtype

Constraints:

  • Use numpy.array() to create the array
  • Input can be 1D or 2D list
  • Return dtype as string
Editor

Test Results

0/0
Run code to see test results.