Questions tagged [sliding-window]

In data analysis, sliding windows are advancing sub-lists inside lists which allow, e.g., computation of a record's change from the previous record or next record. In networking, a sliding window may refer to a flow control technique that maintains windows of sequential frames sent or received without a corresponding acknowledgement.

In data analysis, sliding windows are advancing sub-lists inside lists which allow, e.g., computation of a record's change from the previous record or next record. In SQL in particular, the analytic functions LEAD(), LAG(), and computations OVER() a changing subset of query results involve sliding windows.

In networking, a sliding window may refer to a flow control technique that maintains windows of sequential frames sent or received without a corresponding acknowledgement.

583 questions
5
votes
3 answers

Removing comments with a sliding window without nested while loops

I'm trying to remove comments and strings from a c file with c code. I'll just stick to comments for the examples. I have a sliding window so I only have character n and n-1 at any given moment. I'm trying to figure out an algorithm that does not…
Mike Weber
  • 179
  • 1
  • 1
  • 10
5
votes
2 answers

Sliding window in R

I have a dataframe DF, with two columns A and B shown below: A B 1 0 3 0 4 0 2 1 …
chas
  • 1,565
  • 5
  • 26
  • 54
5
votes
3 answers

SQL - How to show the difference between multiple rows results

I have an SQL 2012 query that gives me the following results: IP_Country ds Percentage ------------------------------------- Australia 01/01/2013 0.70155 Australia 02/01/2013 0.685 Australia 03/01/2013 0.663594 Australia …
4
votes
5 answers

Efficient sliding window sum over a database table

A database has a transactions table with columns: account_id, date, transaction_value (signed integer). Another table (account_value) stores the current total value of each account, which is the sum of all transaction_values per account. It is…
user1147339
  • 41
  • 1
  • 3
4
votes
2 answers

R: Efficiently subsetting dataframe based on time of day

I have a large (150,000x7) dataframe that I intend to use for back-testing and real-time analysis of a financial market. The data represents the condition of an investment vehicle at 5 minute intervals (although holes do exist). It looks like this…
Mike Furlender
  • 3,869
  • 5
  • 47
  • 75
4
votes
2 answers

Using numpy to construct an array with rows extracted from another 2D array as 2x2 blocks

Suppose I have the following 2D array: x = np.array([[10,20,30,40], [50,60,70,80],[90,100,110,120]]) print(x) array([[ 10, 20, 30, 40], [ 50, 60, 70, 80], [ 90, 100, 110, 120]]) I would like to construct a new array, y,…
Amazigh_05
  • 241
  • 1
  • 8
4
votes
5 answers

How do I select n elements of a sequence in windows of m ? (matlab)

Quick MATLAB question. What would be the best/most efficient way to select a certain number of elements, 'n' in windows of 'm'. In other words, I want to select the first 50 elements of a sequence, then elements 10-60, then elements 20-70 ect.…
thepro22
  • 169
  • 1
  • 4
  • 10
4
votes
2 answers

Algorithm: how can't I use sliding window approach for this question?

I encountered this question during an interview. It gives you an array and a threshold and the function should return the length of the shortest, non-empty, contiguous subarray of that array with sum at least past that threshold. So if the array is…
Joji
  • 4,703
  • 7
  • 41
  • 86
4
votes
2 answers

Within-group operations in R (not rolling sum)

I have a dataset comprised of students (id) and the grade they where in every year: library(data.table) set.seed(1) students <- data.table("id" = rep(1:10, each = 10), "year" = rep(2000:2009, 10), "grade" =…
4
votes
3 answers

How to select a sliding window of elements from a list of lists?

Say I have the following list of lists: x = [[1,2,3],[4,5,6],[7,8,9,10]] And I wish to select all 'windows' of size e.g. n=4, staggered by a distance of e.g. d=2: [[1,2,3],[4]] # Starts at position `0` [[3],[4,5,6]] …
iacob
  • 20,084
  • 6
  • 92
  • 119
4
votes
1 answer

Data cleanup that requires iterating over pandas.DataFrame 3 rows at a time

I have some large datasets of sensor readings where occasionally the row will be 0. The heuristic is quite simple: if the previous row and next row were not 0, I assume this is a sensor glitch and I replace this row with the average of the two…
MB.
  • 1,303
  • 12
  • 19
4
votes
3 answers

Efficient way to calculate the "product" of a discrete convolution

I'm looking for an elegant way to compute the "product" of a discrete convolution, instead of the sum. Here is the formula of a discrete convolution: In this case we can use: conv(x,y) Now I would like to implement those operations Of course I…
obchardon
  • 10,614
  • 1
  • 17
  • 33
4
votes
1 answer

Sliding window on time in KDB/Q

There are some functions in Q/KDB that let us aggregate on a sliding window (msum, mavg, etc.). But these functions takes the number of previous rows into account. I'd like a function that would aggregate on a sliding window but with time instead of…
Sithered
  • 481
  • 7
  • 23
4
votes
6 answers

Compute the product of the next n elements in array

I would like to compute the product of the next n adjacent elements of a matrix. The number n of elements to be multiplied should be given in function's input. For example for this input I should compute the product of every 3 consecutive elements,…
esem
  • 153
  • 1
  • 12
4
votes
2 answers

Matrix with sliding window elements

I have time series, and I applying some user defined function to every W elements in time series. Right now I am just using for loop, slide window of size W an apply my function to elements in a window at every iteration. I am using Matlab and it…
Vladimir
  • 369
  • 1
  • 3
  • 12