v9.1.1
Menu

Array Creator

easyFREEArray Creation & BasicsNumPy ArraysNumPy Foundations

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
  • Input: a single integer n=3n = 3, the side length. Three of the four outputs are 3×33 \times 3 matrices (3 rows, each a list of 3 numbers); the fourth is a flat list of length 3.
  • zeros: every entry is 00, so all 9 cells are 0.0. ones: every entry is 11, so all 9 cells are 1.0.
  • range: the integers starting at 00 and stopping before nn, i.e. 0,1,20, 1, 2, giving [0, 1, 2]. Notice it has exactly nn elements and never includes nn itself.
  • identity: the matrix I3I_3 whose entry in row ii, column jj is 11 when i=ji = j and 00 otherwise. Only the 3 diagonal cells are 11: [[1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0]]. Multiplying any 3×33 \times 3 matrix by I3I_3 leaves it unchanged.
  • Output types: the three matrices hold floating-point numbers (0.0, 1.0), while range holds plain integers (0, not 0.0). The printed output must match that distinction exactly.

Constraints

  • Use np.zeros, np.ones, np.arange, np.eye
  • Convert to lists using .tolist()

More from NumPy Foundations

solution.py

Test results

Sign in to run your code against the test cases.