当前位置: 首页>>代码示例>>Python>>正文


Python toolz.sliding_window方法代码示例

本文整理汇总了Python中toolz.sliding_window方法的典型用法代码示例。如果您正苦于以下问题:Python toolz.sliding_window方法的具体用法?Python toolz.sliding_window怎么用?Python toolz.sliding_window使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在toolz的用法示例。


在下文中一共展示了toolz.sliding_window方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: byte_pair_counts

# 需要导入模块: import toolz [as 别名]
# 或者: from toolz import sliding_window [as 别名]
def byte_pair_counts(self, words):
        # type: (Encoder, Iterable[str]) -> Iterable[Counter]
        """ Counts space separated token character pairs:
            [('T h i s </w>', 4}] -> {'Th': 4, 'hi': 4, 'is': 4}
        """
        for token, count in self._progress_bar(self.count_tokens(words).items()):
            bp_counts = Counter()  # type: Counter
            for ngram in token.split(' '):
                bp_counts[ngram] += count
            for ngram_size in range(self.ngram_min, min([self.ngram_max, len(token)]) + 1):
                ngrams = [''.join(ngram) for ngram in toolz.sliding_window(ngram_size, token.split(' '))]

                for ngram in ngrams:
                    bp_counts[''.join(ngram)] += count

            yield bp_counts 
开发者ID:plkmo,项目名称:NLP_Toolkit,代码行数:18,代码来源:bpe_vocab.py

示例2: special_closes

# 需要导入模块: import toolz [as 别名]
# 或者: from toolz import sliding_window [as 别名]
def special_closes(self):
        return [
            (
                time,
                HolidayCalendar([
                    new_years_eve(
                        start_date=start,
                        end_date=end,
                        days_of_week=weekdays,
                    ),
                    christmas_eve(
                        start_date=start,
                        end_date=end,
                        days_of_week=weekdays
                    ),
                ]),
            )
            for (start, time), (end, _) in toolz.sliding_window(
                2,
                toolz.concatv(self.regular_early_close_times, [(None, None)]),
            )
        ] 
开发者ID:quantopian,项目名称:trading_calendars,代码行数:24,代码来源:exchange_calendar_xhkg.py

示例3: pycode_to_body

# 需要导入模块: import toolz [as 别名]
# 或者: from toolz import sliding_window [as 别名]
def pycode_to_body(co, context):
    """
    Convert a Python code object to a list of AST body elements.
    """
    code = Code.from_pycode(co)

    # On each instruction, temporarily store all the jumps to the **next**
    # instruction.  This is used in _make_expr to determine when an expression
    # is part of a short-circuiting expression.
    for a, b in sliding_window(2, code.instrs):
        a._next_target_of = b._target_of
    b._next_target_of = set()

    try:
        body = instrs_to_body(deque(code.instrs), context)
        if context.in_function_block:
            return make_global_and_nonlocal_decls(code.instrs) + body
        return body
    finally:
        # Clean up jump target data.
        for i in code.instrs:
            del i._next_target_of 
开发者ID:llllllllll,项目名称:codetransformer,代码行数:24,代码来源:_343.py

示例4: _group_times

# 需要导入模块: import toolz [as 别名]
# 或者: from toolz import sliding_window [as 别名]
def _group_times(all_days, times, tz, offset):
    elements = [
        days_at_time(
            selection(all_days, start, end),
            time,
            tz,
            offset
        )
        for (start, time), (end, _) in toolz.sliding_window(
            2,
            toolz.concatv(times, [(None, None)])
        )
    ]
    return elements[0].append(elements[1:]) 
开发者ID:quantopian,项目名称:trading_calendars,代码行数:16,代码来源:trading_calendar.py

示例5: special_closes_adhoc

# 需要导入模块: import toolz [as 别名]
# 或者: from toolz import sliding_window [as 别名]
def special_closes_adhoc(self):
        lunar_new_years_eve = (
            chinese_lunar_new_year_dates - pd.Timedelta(days=1)
        )[
            np.in1d(
                chinese_lunar_new_year_dates.weekday,
                [TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY],
            ) & (chinese_lunar_new_year_dates.year >= 2013)
        ].values

        def selection(arr, start, end):
            predicates = []
            if start is not None:
                predicates.append(start.asm8 <= arr)
            if end is not None:
                predicates.append(arr < end.asm8)

            if not predicates:
                return arr

            return arr[np.all(predicates, axis=0)]

        return [
            (time, selection(lunar_new_years_eve, start, end))
            for (start, time), (end, _) in toolz.sliding_window(
                2,
                toolz.concatv(self.regular_early_close_times, [(None, None)]),
            )
        ] 
开发者ID:quantopian,项目名称:trading_calendars,代码行数:31,代码来源:exchange_calendar_xhkg.py

示例6: _get_adjustments_in_range

# 需要导入模块: import toolz [as 别名]
# 或者: from toolz import sliding_window [as 别名]
def _get_adjustments_in_range(self, cf, dts, field):
        if field == 'volume' or field == 'sid':
            return {}
        if cf.adjustment is None:
            return {}
        rf = self._roll_finders[cf.roll_style]
        partitions = []

        rolls = rf.get_rolls(cf.root_symbol, dts[0], dts[-1],
                             cf.offset)

        tc = self._trading_calendar

        adjs = {}

        for front, back in sliding_window(2, rolls):
            front_sid, roll_dt = front
            back_sid = back[0]
            dt = tc.previous_session_label(roll_dt)
            if self._frequency == 'minute':
                dt = tc.open_and_close_for_session(dt)[1]
                roll_dt = tc.open_and_close_for_session(roll_dt)[0]
            partitions.append((front_sid,
                               back_sid,
                               dt,
                               roll_dt))
        for partition in partitions:
            front_sid, back_sid, dt, roll_dt = partition
            last_front_dt = self._bar_reader.get_last_traded_dt(
                self._asset_finder.retrieve_asset(front_sid), dt)
            last_back_dt = self._bar_reader.get_last_traded_dt(
                self._asset_finder.retrieve_asset(back_sid), dt)
            if isnull(last_front_dt) or isnull(last_back_dt):
                continue
            front_close = self._bar_reader.get_value(
                front_sid, last_front_dt, 'close')
            back_close = self._bar_reader.get_value(
                back_sid, last_back_dt, 'close')
            adj_loc = dts.searchsorted(roll_dt)
            end_loc = adj_loc - 1
            adj = self._make_adjustment(cf.adjustment,
                                        front_close,
                                        back_close,
                                        end_loc)
            try:
                adjs[adj_loc].append(adj)
            except KeyError:
                adjs[adj_loc] = [adj]
        return adjs 
开发者ID:enigmampc,项目名称:catalyst,代码行数:51,代码来源:history_loader.py


注:本文中的toolz.sliding_window方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。