Код: Выделить всё
import pandas as pd
import numpy as np
# simple 16 bit integer definitions for example readability
df = pd.Series([0xFFFF, 0xFEAB, 0x0000, 0x1111, 0x5555, 0xAAAA], dtype='uint32')
df.rolling(2).bitwise_and()
Код: Выделить всё
def accumulate_bitwise_and(values):
result = np.uint32(0xFFFFFFFF)
for v in values:
# Upstream Pandas rolling window functionality converts
# inputs to floating point types, hence the conversion
result &= np.uint32(v)
return result
# Short window size of 2 for sample code
accum = df.rolling(2).apply(accumulate_bitwise_and)
accum.drop(accum.index[0], inplace=True) # Drop expected NaN
accum = accum.astype("uint32")
Изменить: добавлю, что размер окна 2 указан только для примера, на самом деле это окна из 100-20000 выборок массивов длиной во многие тысячи выборок.>