當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。