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


Python operator.concat方法代码示例

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


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

示例1: after_training

# 需要导入模块: import operator [as 别名]
# 或者: from operator import concat [as 别名]
def after_training(self, runner, training_stats: TrainingStatistics):
        import matplotlib.pyplot as plt

        losses = map(lambda s: s.losses, training_stats.train_summaries)
        losses = functools.reduce(operator.concat, losses)
        plt.figure()
        plt.plot(np.arange(0, len(losses)), losses)
        plt.ylabel('Loss')
        plt.xlabel('Iteration')

        batch_indices = []
        for summary in training_stats.train_summaries:
            if len(batch_indices) == 0:
                batch_indices.append(summary.n_batches)
            else:
                batch_indices.append(batch_indices[-1] + summary.n_batches)

        for epoch_index in batch_indices:
            plt.axvline(epoch_index, linestyle='dashed', color='black')
        plt.savefig(self.path)
        print('Loss plot written to: {}.png'.format(self.path))
        print('Average inference time: {}'.format(training_stats.current_summary.avg_time_inference)) 
开发者ID:deep500,项目名称:deep500,代码行数:24,代码来源:summary_lossplot.py

示例2: parallel_batch_solver

# 需要导入模块: import operator [as 别名]
# 或者: from operator import concat [as 别名]
def parallel_batch_solver(puzzles, workers=4):
    # Parallel batch solve - Puzzles are chunked into `workers`
    # chunks. A process for each chunk.
    assert len(puzzles) >= workers

    dim = ceil(len(puzzles) / workers)
    chunks = (
        puzzles[k: k + dim] for k in range(0, len(puzzles), dim)
    )

    with ProcessPoolExecutor(max_workers=workers) as executor:
        futures = (
            executor.submit(batch_solve, chunk) for chunk in chunks
        )

        results = (
            future.result() for future in as_completed(futures)
        )

        return reduce(concat, results) 
开发者ID:PacktPublishing,项目名称:Learning-Path-Learn-Web-Development-with-Python,代码行数:22,代码来源:process_solver.py

示例3: _get_all_workflow_fields

# 需要导入模块: import operator [as 别名]
# 或者: from operator import concat [as 别名]
def _get_all_workflow_fields(cls):
        from river.core.workflowregistry import workflow_registry
        return reduce(operator.concat, map(list, workflow_registry.workflows.values()), []) 
开发者ID:javrasya,项目名称:django-river,代码行数:5,代码来源:apps.py

示例4: test_concat

# 需要导入模块: import operator [as 别名]
# 或者: from operator import concat [as 别名]
def test_concat(self):
        self.assertRaises(TypeError, operator.concat)
        self.assertRaises(TypeError, operator.concat, None, None)
        self.assertTrue(operator.concat('py', 'thon') == 'python')
        self.assertTrue(operator.concat([1, 2], [3, 4]) == [1, 2, 3, 4])
        self.assertTrue(operator.concat(Seq1([5, 6]), Seq1([7])) == [5, 6, 7])
        self.assertTrue(operator.concat(Seq2([5, 6]), Seq2([7])) == [5, 6, 7])
        self.assertRaises(TypeError, operator.concat, 13, 29) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:10,代码来源:test_operator.py

示例5: bytearray_concat

# 需要导入模块: import operator [as 别名]
# 或者: from operator import concat [as 别名]
def bytearray_concat(*args):
    """
    Функция конкатенирования нескольких bytearray в один.
    """

    return bytearray_cast(reduce(operator.concat, args)) 
开发者ID:oleg-golovanov,项目名称:pyshtrih,代码行数:8,代码来源:misc.py

示例6: _process_options

# 需要导入模块: import operator [as 别名]
# 或者: from operator import concat [as 别名]
def _process_options(figure, axes, opts=None, **kwargs):
    """
    Processes plotting options.

    Parameters
    ----------
    figure: matplotlib.Figure
    axes: matplotlib.Axes
    opts: dict
        keyword dictionary with custom options
    **kwargs: dict
        standard plotting option (see separate documentation)
    """
    opts = opts or {}

    # Only process items in kwargs that would not have been
    # processed through _extract_kwargs_options()
    filtered_kwargs = {key: value for key, value in kwargs.items()
                       if key not in functools.reduce(operator.concat, _direct_plot_options.values())}

    option_dict = {**opts, **filtered_kwargs}

    for key, value in option_dict.items():
        if key in defaults.SPECIAL_PLOT_OPTIONS:
            _process_special_option(figure, axes, key, value)
        else:
            set_method = getattr(axes, 'set_' + key)
            set_method(value)

    filename = kwargs.get('filename')
    if filename:
        figure.savefig(os.path.splitext(filename)[0] + '.pdf')

    if settings.DESPINE and not axes.name == '3d':
        # Hide the right and top spines
        axes.spines['right'].set_visible(False)
        axes.spines['top'].set_visible(False)

        # Only show ticks on the left and bottom spines
        axes.yaxis.set_ticks_position('left')
        axes.xaxis.set_ticks_position('bottom') 
开发者ID:scqubits,项目名称:scqubits,代码行数:43,代码来源:plotting.py

示例7: binnedMoveActivations

# 需要导入模块: import operator [as 别名]
# 或者: from operator import concat [as 别名]
def binnedMoveActivations(self, top=False):
        gameReports = self.topGames() if top else self.gameReports
        moveActivations = reduce(operator.concat, [gameReport.activations() for gameReport in gameReports])
        return json.dumps([sum([int(moveActivation in range(i,i+10)) for moveActivation in moveActivations]) for i in range(0, 100, 10)][::-1]) 
开发者ID:clarkerubber,项目名称:irwin,代码行数:6,代码来源:AnalysisReport.py

示例8: write_emissions_ncf

# 需要导入模块: import operator [as 别名]
# 或者: from operator import concat [as 别名]
def write_emissions_ncf(infile, outfile):
    from operator import concat
    # initialize hdr_fmts with species count
    hdr_fmts = ["10i60i3ifif", "ffiffffiiiiifff",
                "iiii", "10i" * len(infile.variables.keys())]
    hdrlines = []

    hdrlines.append(
        reduce(concat, [Asc2Int(s) for s in [infile.name, infile.note]]) +
        [infile.ione, len(infile.variables.keys()), infile.start_date,
         infile.start_time, infile.end_date, infile.end_time])

    hdrlines.append(
        [infile.rdum, infile.rdum, infile.iutm, infile.xorg, infile.yorg,
         infile.delx, infile.dely, len(infile.dimensions['COL']),
         len(infile.dimensions['ROW']), len(infile.dimensions['LAY']),
         infile.idum, infile.idum, infile.rdum, infile.rdum, infile.rdum])

    hdrlines.append([infile.ione, infile.ione, len(
        infile.dimensions['COL']), len(infile.dimensions['ROW'])])
    hdrlines.append(reduce(concat, [Asc2Int(s.ljust(10))
                                    for s in infile.variables.keys()]))

    for d, h in zip(hdrlines, hdr_fmts):
        outfile.write(writeline(d, h))

    for ti, (d, t) in enumerate(infile.timerange()):
        ed, et = timeadd((d, t), (0, infile.time_step))
        outfile.write(writeline((d, t, ed, et), 'ifif'))
        for spc in infile.variables.keys():
            var = infile.variables[spc]
            for k in range(len(infile.dimensions['LAY'])):
                outfile.write(writeline(
                    [infile.ione] +
                    Asc2Int(spc.ljust(10)) +
                    var[ti, :, :, k].transpose().ravel().tolist(),
                    '11i' + infile.cell_count * 'f')) 
开发者ID:barronh,项目名称:pseudonetcdf,代码行数:39,代码来源:Write.py

示例9: concat_shape

# 需要导入模块: import operator [as 别名]
# 或者: from operator import concat [as 别名]
def concat_shape(self, values) -> Sequence:
    tuple_values = (tuple(v) for v in values)
    return functools.reduce(operator.concat, tuple_values) 
开发者ID:google,项目名称:TensorNetwork,代码行数:5,代码来源:shell_backend.py

示例10: __concat__

# 需要导入模块: import operator [as 别名]
# 或者: from operator import concat [as 别名]
def __concat__(self, other):
        return Expression((self, other), operator.concat) 
开发者ID:ebranca,项目名称:owasp-pysec,代码行数:4,代码来源:expr.py

示例11: __iconcat__

# 需要导入模块: import operator [as 别名]
# 或者: from operator import concat [as 别名]
def __iconcat__(self, other):
        return Expression((self, other), operator.concat) 
开发者ID:ebranca,项目名称:owasp-pysec,代码行数:4,代码来源:expr.py

示例12: test_concat

# 需要导入模块: import operator [as 别名]
# 或者: from operator import concat [as 别名]
def test_concat(self):
        self.failUnlessRaises(TypeError, operator.concat)
        self.failUnlessRaises(TypeError, operator.concat, None, None)
        self.failUnless(operator.concat('py', 'thon') == 'python')
        self.failUnless(operator.concat([1, 2], [3, 4]) == [1, 2, 3, 4])
        self.failUnless(operator.concat(Seq1([5, 6]), Seq1([7])) == [5, 6, 7])
        self.failUnless(operator.concat(Seq2([5, 6]), Seq2([7])) == [5, 6, 7])
        if not test_support.is_jython:
            # Jython concat is add
            self.failUnlessRaises(TypeError, operator.concat, 13, 29) 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:12,代码来源:test_operator.py

示例13: filter_subregions

# 需要导入模块: import operator [as 别名]
# 或者: from operator import concat [as 别名]
def filter_subregions(subregions: List[SubRegion]) -> List[SubRegion]:
    """ Strips any subregion that is fully contained by another for the same anchor

        Arguments:
            subregions: the subregions to filter

        Returns:
            a sorted list of SubRegions
    """
    if not subregions:
        return subregions

    by_anchor = defaultdict(list)  # type: Dict[str, List[SubRegion]]
    # sort from largest to smallest to avoid complicated replacement logic
    # any sharing an anchor will overlap on that gene anyway
    for sub in sorted(subregions, key=lambda x: x.location.end - x.location.start, reverse=True):
        contained = False
        for other in by_anchor[sub.label]:
            if sub.is_contained_by(other):
                contained = True
                break
        if not contained:
            by_anchor[sub.label].append(sub)
    # flatten the lists and sort back into location order, then anchor
    # mypy doesn't handle this reduce well
    flattened = reduce(operator.concat, by_anchor.values())  # type: ignore
    return sorted(flattened, key=lambda x: (x.location.start, x.location.end, x.label)) 
开发者ID:antismash,项目名称:antismash,代码行数:29,代码来源:__init__.py

示例14: mapcat

# 需要导入模块: import operator [as 别名]
# 或者: from operator import concat [as 别名]
def mapcat(func, iterable):
    return reduce(concat, map(func, iterable)) 
开发者ID:i2y,项目名称:mochi,代码行数:4,代码来源:builtins.py

示例15: concat_deps

# 需要导入模块: import operator [as 别名]
# 或者: from operator import concat [as 别名]
def concat_deps(self, bn):
        # read source
        src = open(os.path.join(self.buildpath, bn), "r").read()
        # update direct dependencies
        deps = []
        self.append_cfile_deps(src, deps)
        # recurse through deps
        # TODO detect cicular deps.
        return reduce(operator.concat, map(self.concat_deps, deps), src) 
开发者ID:thiagoralves,项目名称:OpenPLC_Editor,代码行数:11,代码来源:toolchain_gcc.py


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