Chuyển tới nội dung
Trang chủ » How To Do A Rolling Sum Where The Width Depends On The Sum Itself? Top 3 Favorites

# How To Do A Rolling Sum Where The Width Depends On The Sum Itself? Top 3 Favorites

You are looking for information on the topic “How to do a rolling sum where the width depends on the sum itself?”. boviptaynguyen.com will gather information to answer your questions in this article. Please read this article to the end to find the information you want to see. You can also check out some other related articles here: 226 new posts updated r rolling sum by group, rollify.

## View information about the How to do a rolling sum where the width depends on the sum itself?

• Question: How to do a rolling sum where the width depends on the sum itself?
• Time: Askeded 151 hours ago
• Modified: Askeded 225 hours ago
• View: 11962

### How to do a rolling sum where the width depends on the sum itself?

To perform a rolling sum where the width of the window depends on the sum itself, you can follow these steps:

1. Set an initial window size `w` and starting index `i` to 0.
2. Calculate the sum of the elements from index `i` to `i + w`.
3. If the sum is greater than or equal to a certain threshold value `t`, record it and increment the starting index `i` by 1. Otherwise, increment the window size `w` by 1 and repeat step 2.
4. Repeat steps 2 and 3 until the window size `w` exceeds the length of the input sequence.

Here is an example implementation in Python:

```python```def rolling_sum(sequence, threshold):
i = 0
w = 1
sums = []
while w <= len(sequence):
window_sum = sum(sequence[i:i+w])
if window_sum >= threshold:
sums.append(window_sum)
i += 1
else:
w += 1
return sums
``````

You can call this function with a sequence of numbers and a threshold value to obtain a list of all rolling sums that exceed the threshold:

```python```>>> sequence = [1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> threshold = 12
>>> rolling_sum(sequence, threshold)
[15, 21, 27, 36]
``````

In this example, the function finds all rolling sums that exceed the threshold of 12, where the width of each window is adjusted dynamically based on the sum itself.

### Watch videos related to “How to do a rolling sum where the width depends on the sum itself?”

SQL Query | How to calculate Running Totals and Cumulative Sum ?

## Images related to How to do a rolling sum where the width depends on the sum itself?

Found 27 How to do a rolling sum where the width depends on the sum itself? related images. How To Sum A Column In Excel – 5 Easy Ways

You can see some more information related to How to do a rolling sum where the width depends on the sum itself? here