當前位置: 首頁>>代碼示例>>Python>>正文


Python six.iteritems方法代碼示例

本文整理匯總了Python中six.iteritems方法的典型用法代碼示例。如果您正苦於以下問題:Python six.iteritems方法的具體用法?Python six.iteritems怎麽用?Python six.iteritems使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在six的用法示例。


在下文中一共展示了six.iteritems方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: flatten_recursive

# 需要導入模塊: import six [as 別名]
# 或者: from six import iteritems [as 別名]
def flatten_recursive(cls, item):
        """Flattens (potentially nested) a tuple/dictionary/list to a list."""
        output = []
        if isinstance(item, list):
            output.extend(item)
        elif isinstance(item, tuple):
            output.extend(list(item))
        elif isinstance(item, dict):
            for (_, v) in six.iteritems(item):
                output.append(v)
        else:
            return [item]

        flat_output = []
        for x in output:
            flat_output.extend(cls.flatten_recursive(x))
        return flat_output 
開發者ID:Socialbird-AILab,項目名稱:BERT-Classification-Tutorial,代碼行數:19,代碼來源:modeling_test.py

示例2: get_metrics_with_answer_stats

# 需要導入模塊: import six [as 別名]
# 或者: from six import iteritems [as 別名]
def get_metrics_with_answer_stats(long_answer_stats, short_answer_stats):
  """Generate metrics dict using long and short answer stats."""

  def _get_metric_dict(answer_stats, prefix=''):
    """Compute all metrics for a set of answer statistics."""
    opt_result, pr_table = compute_pr_curves(
        answer_stats, targets=[0.5, 0.75, 0.9])
    f1, precision, recall, threshold = opt_result
    metrics = OrderedDict({
        'best-threshold-f1': f1,
        'best-threshold-precision': precision,
        'best-threshold-recall': recall,
        'best-threshold': threshold,
    })
    for target, recall, precision, _ in pr_table:
      metrics['recall-at-precision>={:.2}'.format(target)] = recall
      metrics['precision-at-precision>={:.2}'.format(target)] = precision

    # Add prefix before returning.
    return dict([(prefix + k, v) for k, v in six.iteritems(metrics)])

  metrics = _get_metric_dict(long_answer_stats, 'long-')
  metrics.update(_get_metric_dict(short_answer_stats, 'short-'))
  return metrics 
開發者ID:google-research-datasets,項目名稱:natural-questions,代碼行數:26,代碼來源:nq_eval.py

示例3: execute

# 需要導入模塊: import six [as 別名]
# 或者: from six import iteritems [as 別名]
def execute(self, *args, **kwargs):
        """
        Called when run through `call_command`. `args` are passed through,
        while `kwargs` is the __dict__ of the return value of
        `self.create_parser('', name)` updated with the kwargs passed to
        `call_command`.
        """
        # Remove internal Django command handling machinery
        kwargs.pop("skip_checks", None)
        parent_ctx = click.get_current_context(silent=True)
        with self.make_context("", list(args), parent=parent_ctx) as ctx:
            # Rename kwargs to to the appropriate destination argument name
            opt_mapping = dict(self.map_names())
            arg_options = {
                opt_mapping.get(key, key): value for key, value in six.iteritems(kwargs)
            }

            # Update the context with the passed (renamed) kwargs
            ctx.params.update(arg_options)

            # Invoke the command
            self.invoke(ctx) 
開發者ID:GaretJax,項目名稱:django-click,代碼行數:24,代碼來源:adapter.py

示例4: save_id_to_path_mapping

# 需要導入模塊: import six [as 別名]
# 或者: from six import iteritems [as 別名]
def save_id_to_path_mapping(self):
    """Saves mapping from submission IDs to original filenames.

    This mapping is saved as CSV file into target directory.
    """
    if not self.id_to_path_mapping:
      return
    with open(self.local_id_to_path_mapping_file, 'w') as f:
      writer = csv.writer(f)
      writer.writerow(['id', 'path'])
      for k, v in sorted(iteritems(self.id_to_path_mapping)):
        writer.writerow([k, v])
    cmd = ['gsutil', 'cp', self.local_id_to_path_mapping_file,
           os.path.join(self.target_dir, 'id_to_path_mapping.csv')]
    if subprocess.call(cmd) != 0:
      logging.error('Can\'t copy id_to_path_mapping.csv to target directory') 
開發者ID:StephanZheng,項目名稱:neural-fingerprinting,代碼行數:18,代碼來源:validate_and_copy_submissions.py

示例5: __str__

# 需要導入模塊: import six [as 別名]
# 或者: from six import iteritems [as 別名]
def __str__(self):
    """Returns human readable representation, which is useful for debugging."""
    buf = StringIO()
    for batch_idx, (batch_id, batch_val) in enumerate(iteritems(self.data)):
      if batch_idx >= TO_STR_MAX_BATCHES:
        buf.write(u'...\n')
        break
      buf.write(u'BATCH "{0}"\n'.format(batch_id))
      for k, v in iteritems(batch_val):
        if k != 'images':
          buf.write(u'  {0}: {1}\n'.format(k, v))
      for img_idx, img_id in enumerate(iterkeys(batch_val['images'])):
        if img_idx >= TO_STR_MAX_IMAGES_PER_BATCH:
          buf.write(u'  ...')
          break
        buf.write(u'  IMAGE "{0}" -- {1}\n'.format(img_id,
                                                   batch_val['images'][img_id]))
      buf.write(u'\n')
    return buf.getvalue() 
開發者ID:StephanZheng,項目名稱:neural-fingerprinting,代碼行數:21,代碼來源:image_batches.py

示例6: save_target_classes_for_batch

# 需要導入模塊: import six [as 別名]
# 或者: from six import iteritems [as 別名]
def save_target_classes_for_batch(self,
                                    filename,
                                    image_batches,
                                    batch_id):
    """Saves file with target class for given dataset batch.

    Args:
      filename: output filename
      image_batches: instance of ImageBatchesBase with dataset batches
      batch_id: dataset batch ID
    """
    images = image_batches.data[batch_id]['images']
    with open(filename, 'w') as f:
      for image_id, image_val in iteritems(images):
        target_class = self.get_target_class(image_val['dataset_image_id'])
        f.write('{0}.png,{1}\n'.format(image_id, target_class)) 
開發者ID:StephanZheng,項目名稱:neural-fingerprinting,代碼行數:18,代碼來源:dataset_helper.py

示例7: write_all_to_datastore

# 需要導入模塊: import six [as 別名]
# 或者: from six import iteritems [as 別名]
def write_all_to_datastore(self):
    """Writes all work pieces into datastore.

    Each work piece is identified by ID. This method writes/updates only those
    work pieces which IDs are stored in this class. For examples, if this class
    has only work pieces with IDs  '1' ... '100' and datastore already contains
    work pieces with IDs '50' ... '200' then this method will create new
    work pieces with IDs '1' ... '49', update work pieces with IDs
    '50' ... '100' and keep unchanged work pieces with IDs '101' ... '200'.
    """
    client = self._datastore_client
    with client.no_transact_batch() as batch:
      parent_key = client.key(KIND_WORK_TYPE, self._work_type_entity_id)
      batch.put(client.entity(parent_key))
      for work_id, work_val in iteritems(self._work):
        entity = client.entity(client.key(KIND_WORK, work_id,
                                          parent=parent_key))
        entity.update(work_val)
        batch.put(entity) 
開發者ID:StephanZheng,項目名稱:neural-fingerprinting,代碼行數:21,代碼來源:work_data.py

示例8: init_from_adversarial_batches

# 需要導入模塊: import six [as 別名]
# 或者: from six import iteritems [as 別名]
def init_from_adversarial_batches(self, adv_batches):
    """Initializes work pieces from adversarial batches.

    Args:
      adv_batches: dict with adversarial batches,
        could be obtained as AversarialBatches.data
    """
    for idx, (adv_batch_id, adv_batch_val) in enumerate(iteritems(adv_batches)):
      work_id = ATTACK_WORK_ID_PATTERN.format(idx)
      self.work[work_id] = {
          'claimed_worker_id': None,
          'claimed_worker_start_time': None,
          'is_completed': False,
          'error': None,
          'elapsed_time': None,
          'submission_id': adv_batch_val['submission_id'],
          'shard_id': None,
          'output_adversarial_batch_id': adv_batch_id,
      } 
開發者ID:StephanZheng,項目名稱:neural-fingerprinting,代碼行數:21,代碼來源:work_data.py

示例9: _write_to_datastore

# 需要導入模塊: import six [as 別名]
# 或者: from six import iteritems [as 別名]
def _write_to_datastore(self):
    """Writes all submissions to datastore."""
    # Populate datastore
    roots_and_submissions = zip([ATTACKS_ENTITY_KEY,
                                 TARGET_ATTACKS_ENTITY_KEY,
                                 DEFENSES_ENTITY_KEY],
                                [self._attacks,
                                 self._targeted_attacks,
                                 self._defenses])
    client = self._datastore_client
    with client.no_transact_batch() as batch:
      for root_key, submissions in roots_and_submissions:
        batch.put(client.entity(client.key(*root_key)))
        for k, v in iteritems(submissions):
          entity = client.entity(client.key(*(root_key + [KIND_SUBMISSION, k])))
          entity['submission_path'] = v.path
          entity.update(participant_from_submission_path(v.path))
          batch.put(entity) 
開發者ID:StephanZheng,項目名稱:neural-fingerprinting,代碼行數:20,代碼來源:submissions.py

示例10: __str__

# 需要導入模塊: import six [as 別名]
# 或者: from six import iteritems [as 別名]
def __str__(self):
    """Returns human readable representation, useful for debugging purposes."""
    buf = StringIO()
    title_values = zip([u'Attacks', u'Targeted Attacks', u'Defenses'],
                       [self._attacks, self._targeted_attacks, self._defenses])
    for idx, (title, values) in enumerate(title_values):
      if idx >= TO_STR_MAX_SUBMISSIONS:
        buf.write('...\n')
        break
      buf.write(title)
      buf.write(u':\n')
      for k, v in iteritems(values):
        buf.write(u'{0} -- {1}   {2}\n'.format(k, v.path,
                                               str(v.participant_id)))
      buf.write(u'\n')
    return buf.getvalue() 
開發者ID:StephanZheng,項目名稱:neural-fingerprinting,代碼行數:18,代碼來源:submissions.py

示例11: handle_class

# 需要導入模塊: import six [as 別名]
# 或者: from six import iteritems [as 別名]
def handle_class(val, class_name):
    cls_errors = []
    docstring = inspect.getdoc(val)
    if docstring is None:
        cls_errors.append((class_name,
                           '**missing** class-level docstring'))
    else:
        cls_errors = [
            (e,) for e in
            NumpyClassDocString(docstring, class_name, val).get_errors()
        ]
        # Get public methods and parse their docstrings
        methods = dict(((name, func) for name, func in inspect.getmembers(val)
                        if not name.startswith('_') and callable(func) and
                        type(func) is not type))
        for m_name, method in six.iteritems(methods):
            # skip error check if the method was inherited
            # from a parent class (which means it wasn't
            # defined in this source file)
            if inspect.getmodule(method) is not None:
                continue
            cls_errors.extend(handle_method(method, m_name, class_name))
    return cls_errors 
開發者ID:StephanZheng,項目名稱:neural-fingerprinting,代碼行數:25,代碼來源:docscrape.py

示例12: map_cpg_tables

# 需要導入模塊: import six [as 別名]
# 或者: from six import iteritems [as 別名]
def map_cpg_tables(cpg_tables, chromo, chromo_pos):
    """Maps values from cpg_tables to `chromo_pos`.

    Positions in `cpg_tables` for `chromo`  must be a subset of `chromo_pos`.
    Inserts `dat.CPG_NAN` for uncovered positions.
    """
    chromo_pos.sort()
    mapped_tables = OrderedDict()
    for name, cpg_table in six.iteritems(cpg_tables):
        cpg_table = cpg_table.loc[cpg_table.chromo == chromo]
        cpg_table = cpg_table.sort_values('pos')
        mapped_table = map_values(cpg_table.value.values,
                                  cpg_table.pos.values,
                                  chromo_pos)
        assert len(mapped_table) == len(chromo_pos)
        mapped_tables[name] = mapped_table
    return mapped_tables 
開發者ID:kipoi,項目名稱:models,代碼行數:19,代碼來源:dataloader_m.py

示例13: forget_subject

# 需要導入模塊: import six [as 別名]
# 或者: from six import iteritems [as 別名]
def forget_subject(sid):
    '''
    forget_subject(sid) causes neuropythy's hcp module to forget about cached data for the subject
      with subject id sid. The sid may be any sid that can be passed to the subject() function.
    
    This function is useful for batch-processing of subjects in a memory-limited environment; e.g.,
    if you run out of memory while processing hcp subjects it is possibly because neuropythy is
    caching all of their data instead of freeing it.
    '''
    sub = subject(sid)
    if sub.path in subject._cache:
        del subject._cache[sub.path]
    else:
        for (k,v) in six.iteritems(subject._cache):
            if v is sub:
                del subject._cache[k]
                break
    return None 
開發者ID:noahbenson,項目名稱:neuropythy,代碼行數:20,代碼來源:core.py

示例14: to_image_spec

# 需要導入模塊: import six [as 別名]
# 或者: from six import iteritems [as 別名]
def to_image_spec(img, **kw):
    '''
    to_image_spec(img) yields a dictionary of meta-data for the given nibabel image object img.
    to_image_spec(hdr) yields the equivalent meta-data for the given nibabel image header.

    Note that obj may also be a mapping object, in which case it is returned verbatim.
    '''
    if pimms.is_vector(img,'int') and is_tuple(img) and len(img) < 5:
        r = image_array_to_spec(np.zeros(img))
    elif pimms.is_map(img):    r = img
    elif is_image_header(img): r = image_header_to_spec(img)
    elif is_image(img):        r = image_to_spec(img)
    elif is_image_array(img):  r = image_array_to_spec(img)
    else: raise ValueError('cannot convert object of type %s to image-spec' % type(img))
    if len(kw) > 0: r = {k:v for m in (r,kw) for (k,v) in six.iteritems(m)}
    # normalize the entries
    for (k,aliases) in six.iteritems(imspec_aliases):
        if k in r: continue
        for al in aliases:
            if al in r:
                val = r[al]
                r = pimms.assoc(pimms.dissoc(r, al), k, val)
                break
    return r 
開發者ID:noahbenson,項目名稱:neuropythy,代碼行數:26,代碼來源:images.py

示例15: forget_subject

# 需要導入模塊: import six [as 別名]
# 或者: from six import iteritems [as 別名]
def forget_subject(sid):
    '''
    forget_subject(sid) causes neuropythy's freesurfer module to forget about cached data for the
      subject with subject id sid. The sid may be any sid that can be passed to the subject()
      function.

    This function is useful for batch-processing of subjects in a memory-limited environment; e.g.,
    if you run out of memory while processing FreeSurfer subjects it is possibly because neuropythy
    is caching all of their data instead of freeing it.
    '''
    sub = subject(sid)
    if sub.path in subject._cache:
        del subject._cache[sub.path]
    for (k,v) in six.iteritems(subject._cache):
        if pimms.is_tuple(k) and k[-1] == sub.path:
            del subject._cache[k]
    return None 
開發者ID:noahbenson,項目名稱:neuropythy,代碼行數:19,代碼來源:core.py


注:本文中的six.iteritems方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。