Array Statistics
Problem Statement
Calculate basic statistics of a NumPy array.
Background
NumPy provides statistical functions:
- np.sum(): Sum of elements
- np.mean(): Average
- np.min(), np.max(): Min and max
- np.std(): Standard deviation
Your Task
Write a function array_stats(arr) that returns a dictionary with:
- "sum": Sum of all elements
- "mean": Mean (average), rounded to 2 decimals
- "min": Minimum value
- "max": Maximum value
- "std": Population standard deviation (divide by , not ), rounded to 2 decimals
Output Format
Return a dictionary with exactly these five keys.
Example
[1, 2, 3, 4, 5]
{'sum': 15, 'mean': 3.0, 'min': 1, 'max': 5, 'std': 1.41}- Input:
arris a 1-D array of five integers, , so . - Sum and mean: , and the mean is , shown as
3.0(a decimal, since averages are generally not whole). - Min and max: the smallest and largest entries are
1and5; like the sum, they stay whole numbers because every input is an integer. - Standard deviation: the deviations from the mean are , whose squares are (total ). Dividing by gives a variance of , so , which rounds to
1.41at 2 decimal places. - Output: a dictionary with exactly the keys
sum,mean,min,max,std. - Notice that dividing by instead would give , which is not the expected answer. A constant array such as has every deviation zero, so its
stdis0.0.
Constraints
- Round mean and std to 2 decimal places
- Array will have at least 1 element