Create Arrays with Special Values
Problem Statement
Create NumPy arrays filled with special values (zeros, ones, specific values).
Background
NumPy provides functions to create pre-filled arrays:
- np.zeros(shape): Array of zeros
- np.ones(shape): Array of ones
- np.full(shape, value): Array filled with specific value
- np.empty(shape): Uninitialized array
Your Task
Write a function create_special_arrays(rows, cols) that returns a dictionary with:
- "zeros": Array of zeros as nested list
- "ones": Array of ones as nested list
- "fives": Array filled with 5s as nested list
Output Format
Return a dictionary with exactly these three keys.
Example
rows = 2, cols = 3
{'zeros': [[0.0, 0.0, 0.0], [0.0, 0.0, 0.0]], 'ones': [[1.0, 1.0, 1.0], [1.0, 1.0, 1.0]], 'fives': [[5, 5, 5], [5, 5, 5]]}- Inputs:
rowsandcolsfix the shape of every matrix: 2 rows, each holding 3 entries, so each matrix has entries. - Math: three constant matrices of that shape. The zero matrix has for every row and column ; the all-ones matrix has ; the third has . No entry depends on its position, only on which matrix it belongs to.
- Output shape: each matrix is written row by row as a list of 2 rows, each row a list of 3 numbers, e.g.
[[1.0, 1.0, 1.0], [1.0, 1.0, 1.0]]. The three matrices sit under the keyszeros,onesandfives. - Notice the number types: the zeros and ones appear as real numbers (
0.0,1.0), while the fives appear as whole numbers (5). The printed output must match this exactly. - Swapping the arguments to gives 3 rows of 2 entries each, not the same lists.
Constraints
- Use np.zeros(), np.ones(), np.full()
- rows and cols will be positive integers