Create Range Arrays
Problem Statement
Create NumPy arrays with sequential or evenly spaced values.
Background
- np.arange(start, stop, step): Like Python range, but returns array
- np.linspace(start, stop, num): num evenly spaced values
Your Task
Write a function create_ranges(start, stop, num_points) that returns a dictionary with:
- "arange": Array from start to stop (exclusive) with step 1
- "linspace": num_points evenly spaced values from start to stop (inclusive)
Round linspace values to 2 decimal places.
Output Format
Return a dictionary with exactly these two keys. Both values must be plain Python lists (not NumPy arrays), as shown in the sample.
Example
start = 0, stop = 5, num_points = 5
{'arange': [0, 1, 2, 3, 4], 'linspace': [0.0, 1.25, 2.5, 3.75, 5.0]}- Inputs:
startandstopbound the interval;num_pointsonly affects the second list. arange: integers stepping by from up to but not including , i.e. . That gives values,[0, 1, 2, 3, 4], and since every value is an integer they print without a decimal point.linspace: both endpoints are included, so points create equal gaps. The spacing is , and the -th value is for : .- Rounding to 2 decimal places changes nothing here, but the values are floats, so the list is
[0.0, 1.25, 2.5, 3.75, 5.0]. - Notice: the first list's length is and it never reaches
stop; the second always has exactlynum_pointsvalues and always ends atstop. Withstart,stop, points, the spacing becomes .
Constraints
- Round linspace to 2 decimal places
- start < stop