sliding-window

postgres generate array using slide window

╄→гoц情女王★ 提交于 2021-02-10 14:41:09
问题 I'm trying to figure out how to a query to generate an ARRAY given a sliding window over a character column with Postgre. For example, if I have this: pid <chr> 1 WP_096038768.1 2 WP_013465871.1 3 WP_058155244.1 4 WP_011329269.1 5 WP_058374608.1 6 WP_089368983.1 7 WP_096739105.1 8 WP_089346667.1 9 WP_096041177.1 10 WP_010553306.1 ... I want a sliding window of size 1 before and after the row. The result is this: pid g <chr> <chr> 1 WP_013465871.1 WP_096038768.1,WP_013465871.1,WP_058155244.1 2

Looping through n x n matrix with a smaller matrix of certain size with numpy arrays

北慕城南 提交于 2021-02-08 08:23:39
问题 I'm currently having the following issue, given an array let's say for simplicity a 4 x 4 array (I'm actually working with 512 x 512 ) X = np.array([[3, 5, 2, 4], [7, 6, 8, 8], [1, 6, 7, 7], [2, 1, 3, 4]]) I would like to loop/slide around the array in a way that I can save new arrays in the form np.array([3,5],[7,6]), np.array([2,4], [8,8]), np.array([1,6],[2,1]), np.array ([7,7],[1,4]) and so on (Ideally that I could choose the step and the size of my "sliding" window). Also I would like to

Rolling average without timestamp in pyspark

我怕爱的太早我们不能终老 提交于 2021-01-28 11:42:08
问题 We can find the rolling/moving average of a time series data using window function in pyspark. The data I am dealing with doesn't have any timestamp column but it does have a strictly increasing column frame_number . Data looks like this. d = [ {'session_id': 1, 'frame_number': 1, 'rtd': 11.0, 'rtd2': 11.0,}, {'session_id': 1, 'frame_number': 2, 'rtd': 12.0, 'rtd2': 6.0}, {'session_id': 1, 'frame_number': 3, 'rtd': 4.0, 'rtd2': 233.0}, {'session_id': 1, 'frame_number': 4, 'rtd': 110.0, 'rtd2'

Rolling average without timestamp in pyspark

冷暖自知 提交于 2021-01-28 11:25:33
问题 We can find the rolling/moving average of a time series data using window function in pyspark. The data I am dealing with doesn't have any timestamp column but it does have a strictly increasing column frame_number . Data looks like this. d = [ {'session_id': 1, 'frame_number': 1, 'rtd': 11.0, 'rtd2': 11.0,}, {'session_id': 1, 'frame_number': 2, 'rtd': 12.0, 'rtd2': 6.0}, {'session_id': 1, 'frame_number': 3, 'rtd': 4.0, 'rtd2': 233.0}, {'session_id': 1, 'frame_number': 4, 'rtd': 110.0, 'rtd2'

Sliding windows - measuring length of observations on each looped window

蓝咒 提交于 2020-08-10 19:32:07
问题 Let's analyse this sample code where zip() is used to create different windows from a dataset and return them in loop. months = [Jan, Feb, Mar, Apr, May] for x, y in zip(months, months[1:]): print(x, y) # Output of each window will be: Jan Feb Feb Mar Mar Apr Apr May Let's suppose that now I want to calculate the respective length percentage between the months used in each window. Example in steps: When returning the first window (Jan Feb), I want to calculate the % length of Jan over the

Sliding windows - measuring length of observations on each looped window

倖福魔咒の 提交于 2020-08-10 19:32:05
问题 Let's analyse this sample code where zip() is used to create different windows from a dataset and return them in loop. months = [Jan, Feb, Mar, Apr, May] for x, y in zip(months, months[1:]): print(x, y) # Output of each window will be: Jan Feb Feb Mar Mar Apr Apr May Let's suppose that now I want to calculate the respective length percentage between the months used in each window. Example in steps: When returning the first window (Jan Feb), I want to calculate the % length of Jan over the

Python Sliding Window on sentence string

喜夏-厌秋 提交于 2020-07-03 08:11:06
问题 I'm looking for a sliding window splitter of string composed with words with window size N. Input : "I love food and I like drink" , window size 3 Output : [ "I love food", "love food and", "food and I", "and I like" .....] All the suggestions of window sliding is around sequence of string, no terms. Is there something out of the box? 回答1: You can use iterator with different offsets and zip all of them. >>> arr = "I love food. blah blah".split() >>> its = [iter(arr), iter(arr[1:]), iter(arr[2

Generalized method for rolling or sliding window over array axis

穿精又带淫゛_ 提交于 2020-06-27 01:09:54
问题 How can I efficiently make an array of sliding windows across an arbitrary axis of a given array? For example, if I have the following array: [[ 0 1 2 3 4] [ 5 6 7 8 9] [10 11 12 13 14] [15 16 17 18 19] [20 21 22 23 24] [25 26 27 28 29]] And a window size of 4, I would like to be able to make a sliding window across the first dimension, like this: [[[ 0 1 2 3 4] [ 5 6 7 8 9] [10 11 12 13 14] [15 16 17 18 19]] [[ 5 6 7 8 9] [10 11 12 13 14] [15 16 17 18 19] [20 21 22 23 24]] [[10 11 12 13 14]