TensorTonicTensorTonic
Problems
Study PlansProjectsNewInterviewPricingFeedback
Problems
Loading...
1 / 1

Seasonal Average

Time Series
Medium

Seasonal averaging estimates the typical value at each position of a repeating cycle. Position p contains the observations at indices p, p + period, p + 2 * period, and so on.

For every position from 0 through period - 1, average all observations belonging to that position. Return the period seasonal averages in position order.

Loading visualization...

Examples

Input: series = [1, 2, 3, 4, 5, 6], period = 3

Output: [2.5, 3.5, 4.5]

Explanation: Seasonal position 0 contains 1 and 4, position 1 contains 2 and 5, and position 2 contains 3 and 6.

Input: series = [1, 2, 1, 2, 1, 2], period = 2

Output: [1.0, 2.0]

Hint 1

For position p, iterate with range(p, len(series), period).

Hint 2

Average each collected seasonal group independently.

Requirements

  • Group observations by their index modulo period.
  • Compute the arithmetic mean of every seasonal group.
  • Return exactly period floating-point values.

Constraints

  • 1 <= period <= len(series).
  • series contains numeric values.
  • Time limit: 300 ms.
Try Similar Problems
Double Exponential SmoothingExponential Moving AverageSimple Moving AverageWeighted Moving AverageLag Features

Sign in to take notes on this problem

Case 1
Case 2

Accepts: array

Accepts: number

You must run your code first.
PrevNext

Seasonal Average

Time Series
Medium

Seasonal averaging estimates the typical value at each position of a repeating cycle. Position p contains the observations at indices p, p + period, p + 2 * period, and so on.

For every position from 0 through period - 1, average all observations belonging to that position. Return the period seasonal averages in position order.

Loading visualization...

Examples

Input: series = [1, 2, 3, 4, 5, 6], period = 3

Output: [2.5, 3.5, 4.5]

Explanation: Seasonal position 0 contains 1 and 4, position 1 contains 2 and 5, and position 2 contains 3 and 6.

Input: series = [1, 2, 1, 2, 1, 2], period = 2

Output: [1.0, 2.0]

Hint 1

For position p, iterate with range(p, len(series), period).

Hint 2

Average each collected seasonal group independently.

Requirements

  • Group observations by their index modulo period.
  • Compute the arithmetic mean of every seasonal group.
  • Return exactly period floating-point values.

Constraints

  • 1 <= period <= len(series).
  • series contains numeric values.
  • Time limit: 300 ms.
Try Similar Problems
Double Exponential SmoothingExponential Moving AverageSimple Moving AverageWeighted Moving AverageLag Features

Sign in to take notes on this problem

Case 1
Case 2

Accepts: array

Accepts: number

You must run your code first.