Python: create a distribution from a list based on number of items that fall within certain ranges
Date : March 29 2020, 07:55 AM
will help you I tagged this question with poisson as I am not sure if it will be helpful in this case. , If data is always sorted, a compact approach might be: import itertools as it
d = [k+1 for k, L in
((k, len(list(g))) for k, g in it.groupby(data,key=lambda x:x//10))
if L>=3]
def divby10(x): return x//10
distribution = []
for k, g in it.groupby(data, key=divby10):
L = len(list(g))
if L < 3: continue
distribution.append(k+1)

Computing number of days which fall between predefined date ranges
Date : March 29 2020, 07:55 AM
Hope this helps this is a possible solution algorithm: find all rate periods that have a nonempty intersection with the booking period for each rate period found in (1), compute the number of days in its intersection with the booking period, and multiply by period's rate the remaining number of days (i.e. length of the booking period in days less sum of all days found in (2) are your base rate days SELECT * FROM rates
WHERE NOT (booking_end < period_start OR
booking_start > period_end)

Rounding Numbers that fall within variable number of ranges in Python
Date : March 29 2020, 07:55 AM
With these it helps This is easy to do with basic mathematical operations in a list comprehension: numRanges = 3
lstMin = min(lst)
lstMax = max(lst) + 1e12 # small value added to avoid floating point rounding issues
step = (lstMax  lstMin) / numRanges
range_numbers = [int((xlstMin) / step) for x in lst]

Finding indices that fall between given ranges
Tag : python , By : Pepe Araya
Date : March 29 2020, 07:55 AM
this will help The shortcut notation B4X1 < dataX < B4X2 doesn't work. You need to do the following: OK = (B4X1 < dataX) & (dataX < B4X2) & (B4Y1 < dataY) & (dataY < B4Y2)
In [23]: dataX = np.random.randint(200, size=100)
In [24]: dataY = np.random.randint(200, size=100)
In [25]: %timeit OK = (B4X1 < dataX) & (dataX < B4X2) & (B4Y1 < dataY) & (dataY < B4Y2)
10000 loops, best of 3: 23.6 µs per loop
In [26]: %timeit OK = np.logical_and.reduce([B4X1<dataX,dataX<B4X2,B4Y1<dataY,dataY<B4Y2])
10000 loops, best of 3: 26.7 µs per loop
In [27]: %timeit for i in dataX: OK = (B4X1 < i and i < B4X2) and (B4Y1 < i and i < B4Y2)
1000 loops, best of 3: 449 µs per loop
In [28]: %timeit for i in dataX: OK = (B4X1 < i and i < B4X2) and (B4Y1 < i and i < B4Y2)
1000 loops, best of 3: 329 µs per loop

Remove ranges that fall within other ranges
Tag : php , By : desmiserables
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , You were almost there... But because you are using >= and <=, your forgot to prevent the $current item from comparing against itself... I added $my !== $current $x = array_filter($mys, function($current) use($mys) {
foreach ($mys as $my):
if ($my !== $current and $current['start'] >= $my['start'] and $current['end'] <= $my['end'])
return false;
endforeach;
return true;
});
$x = array_filter( $mys, function( $current, $currentKey ) use( $mys ) {
foreach ( $mys as $myKey => $my ):
if ( $currentKey != $myKey and $current['start'] >= $my['start'] and $current['end'] <= $my['end'] )
return false;
endforeach;
return true;
}, ARRAY_FILTER_USE_BOTH );

