📘
Create NumPy Array from List
EasyNumPy Basics
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:
- Converts the input list to a NumPy array
- 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
Python 3.13.1
Test Results
0/0Run code to see test results.