I'm struggling with creating a moving window sum function that calculates the number of True
values in a given numpy Boolean array my_array
, with a window size of n
and in jumping steps of s
.
For example, consider array my_array = [True, True, False, False, True, False, True]
the sum of a moving window of size n = 2
and with steps s = 2
should yield result = [2, 0, 1, 1]
, notice that the last window contains only one value.
I was trying my luck with itertools
but to no avail.
Any help would be kindly appreciated.