Problems
Loading...
1 / 1

Mean, Median, Mode

Probability and Statistics
Easy

Compute the mean, median, and mode of a 1D numeric array.

Function Arguments

  • x: list or array - Numeric data
Loading visualization...

Examples

Input: x=[1,1,2,3]

Output: mean=1.75, median=1.5, mode=1

Input: x=[5]

Output: mean=5.0, median=5.0, mode=5

Input: x=[1,2,2,3,3]

Output: mean=2.2, median=2.0, mode=2

Hint 1

Use np.mean() and np.median() for mean and median.

Hint 2

Use Counter() to find frequencies and min() for smallest mode.

Hint 3

Convert all results to float() before returning.

Requirements

  • Return tuple: (mean, median, mode)
  • All values: scalar floats
  • Mode = smallest value with highest frequency
  • Convert x to NumPy array

Constraints

  • len(x) ≥ 1
  • NumPy + collections allowed; time limit: 300ms
Try Similar Problems