📘
Array Creator
EasyNumPy Arrays
Problem Statement
Create NumPy arrays using different methods.
Background
NumPy provides many ways to create arrays:
- np.array([1, 2, 3]) - from list
- np.zeros((m, n)) - array of zeros
- np.ones((m, n)) - array of ones
- np.arange(start, stop, step) - range
- np.linspace(start, stop, num) - evenly spaced
Your Task
Write a function create_arrays(n) that returns a dictionary with different arrays.
Output Format
Return a dictionary with:
- "zeros": n×n matrix of zeros (list of lists)
- "ones": n×n matrix of ones (list of lists)
- "range": Array from 0 to n-1 (list)
- "identity": n×n identity matrix (list of lists)
Example:
Input:
n = 3
Output:
{'zeros': [[0.0, 0.0, 0.0], ...], 'ones': [[1.0, ...], ...], ...}Reasoning:
np.zeros((3,3)), np.ones((3,3)), np.arange(3), np.eye(3)
Constraints:
- Use np.zeros, np.ones, np.arange, np.eye
- Convert to lists using .tolist()
Editor
Python 3.13.1
Test Results
0/0Run code to see test results.