本文整理汇总了Python中six.moves.izip函数的典型用法代码示例。如果您正苦于以下问题:Python izip函数的具体用法?Python izip怎么用?Python izip使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了izip函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: safe_str_cmp
def safe_str_cmp(a, b):
"""This function compares strings in somewhat constant time. This
requires that the length of at least one string is known in advance.
Returns `True` if the two strings are equal, or `False` if they are not.
.. versionadded:: 0.7
"""
if isinstance(a, text_type):
a = a.encode('utf-8')
if isinstance(b, text_type):
b = b.encode('utf-8')
if _builtin_safe_str_cmp is not None:
return _builtin_safe_str_cmp(a, b)
if len(a) != len(b):
return False
rv = 0
if PY2:
for x, y in izip(a, b):
rv |= ord(x) ^ ord(y)
else:
for x, y in izip(a, b):
rv |= x ^ y
return rv == 0
开发者ID:bibi21000,项目名称:janitoo_db,代码行数:28,代码来源:security.py
示例2: todok
def todok(self):
from .dok import dok_matrix
dok = dok_matrix((self.shape), dtype=self.dtype)
dok.update(izip(izip(self.row, self.col), self.data))
return dok
开发者ID:jsren,项目名称:sdp-vision-env,代码行数:8,代码来源:coo.py
示例3: __getitem__
def __getitem__(self, key):
try:
if isinstance(key, int) and (key >= 0):
if key in self.cache:
return self.cache[key]
elif key < self.stop:
self.stop = 0
self.iterator = iter(self.f())
delta = key - self.stop
result = next(islice(self.iterator, delta, delta + 1))
self.cache[key] = result
self.stop = key + 1
return result
elif isinstance(key, slice):
if key.start is None and key.stop is None:
# Whole sequence is asked
return list(self.f())
start = key.start or 0
step = key.step or 1
indexes = count(start, step)
index_upd = start
while (key.stop is None or index_upd < key.stop) and index_upd in self.cache:
index_upd += step
if index_upd < self.stop and (key.stop is None or index_upd < key.stop):
self.iterator = iter(self.f())
result = list(islice(self.iterator, start, key.stop, step))
for i, value in izip(indexes, result):
self.cache[i] = value
self.stop = i + 1 if key.stop is None else key.stop
return result
else:
result = [self.cache[i] for i in six.moves.xrange(start, index_upd, step)]
if key.stop is None:
result_upd = list(islice(self.iterator, index_upd - self.stop, None, step))
elif index_upd < key.stop:
result_upd = list(islice(self.iterator, index_upd - self.stop, key.stop - self.stop, step))
else:
result_upd = []
for i, value in izip(indexes, result_upd):
self.cache[i] = value
self.stop = key.stop
return result + result_upd
else:
raise KeyError("Key must be non-negative integer or slice, not {}"
.format(key))
except StopIteration:
self.iterator = self.f()
self.stop = 0
raise
开发者ID:felixonmars,项目名称:zerodb,代码行数:57,代码来源:iter.py
示例4: lazy_load_trees
def lazy_load_trees(skeleton_ids, node_properties):
""" Return a lazy collection of pairs of (long, DiGraph)
representing (skeleton_id, tree).
The node_properties is a list of strings, each being a name of a column
in the django model of the Treenode table that is not the treenode id, parent_id
or skeleton_id. """
values_list = ('id', 'parent_id', 'skeleton_id')
props = tuple(set(node_properties) - set(values_list))
values_list += props
ts = Treenode.objects.filter(skeleton__in=skeleton_ids) \
.order_by('skeleton') \
.values_list(*values_list)
skid = None
tree = None
for t in ts:
if t[2] != skid:
if tree:
yield (skid, tree)
# Prepare for the next one
skid = t[2]
tree = DiGraph()
fields = {k: v for k,v in izip(props, islice(t, 3, 3 + len(props)))}
tree.add_node(t[0], fields)
if t[1]:
# From child to parent
tree.add_edge(t[0], t[1])
if tree:
yield (skid, tree)
开发者ID:davidhildebrand,项目名称:CATMAID,代码行数:33,代码来源:tree_util.py
示例5: refresh
def refresh(self, items, consistent=False):
"""
Overwrite model data with freshest from database
Parameters
----------
items : list or :class:`~flywheel.models.Model`
Models to sync
consistent : bool, optional
If True, force a consistent read from the db. (default False)
"""
if isinstance(items, Model):
items = [items]
if not items:
return
tables = defaultdict(list)
for item in items:
tables[item.meta_.ddb_tablename(self.namespace)].append(item)
for tablename, items in six.iteritems(tables):
keys = [item.pk_dict_ for item in items]
results = self.dynamo.batch_get(tablename, keys,
consistent=consistent)
for item, data in izip(items, results):
with item.loading_(self):
for key, val in data.items():
item.set_ddb_val_(key, val)
开发者ID:zzugg,项目名称:flywheel,代码行数:29,代码来源:engine.py
示例6: get_sample
def get_sample(self, fit, factor=4, num=1):
vals = numpy.array(fit.model.thawedpars)
scales = self.scale.get_scales(fit)
samples = [numpy.random.uniform(val - factor * abs(scale),
val + factor * abs(scale),
int(num)) for val, scale in izip(vals, scales)]
return numpy.asarray(samples).T
开发者ID:DougBurke,项目名称:sherpa,代码行数:7,代码来源:sample.py
示例7: get_scales
def get_scales(self, fit, myscales=None):
scales = []
thawedpars = [par for par in fit.model.pars if not par.frozen]
if None == myscales:
oldestmethod = fit.estmethod
covar = Covariance()
covar.config['sigma'] = self.sigma
fit.estmethod = Covariance()
try:
r = fit.est_errors()
finally:
fit.estmethod = oldestmethod
for par, val, lo, hi in izip(thawedpars, r.parvals, r.parmins, r.parmaxes):
scale = None
if lo is not None and hi is not None:
scale = numpy.abs(lo)
else:
warning("Covariance failed for '%s', trying Confidence..." %
par.fullname)
conf = Confidence()
conf.config['sigma'] = self.sigma
fit.estmethod = conf
try:
t = fit.est_errors(parlist=(par,))
if t.parmins[0] is not None and t.parmaxes[0] is not None:
scale = numpy.abs(t.parmins[0])
else:
if t.parmins[0] is None and t.parmaxes[0] is not None:
scale = numpy.abs(t.parmaxes[0])
else:
warning('1 sigma bounds for parameter ' +
par.fullname +
' could not be found, using soft limit minimum')
if 0.0 == numpy.abs(par.min):
scale = 1.0e-16
else:
scale = numpy.abs(par.min)
finally:
fit.estmethod = oldestmethod
scales.append(scale)
else:
if not numpy.iterable(myscales):
raise TypeError(
"scales option must be iterable of length %d " % len(thawedpars))
scales = list(map(abs, myscales))
scales = numpy.asarray(scales).transpose()
return scales
开发者ID:DougBurke,项目名称:sherpa,代码行数:60,代码来源:sample.py
示例8: return_docs
def return_docs(self, return_doc_cb):
"""Return the changed documents and their last change generation
repeatedly invoking the callback return_doc_cb.
The final step of a sync exchange.
:param: return_doc_cb(doc, gen, trans_id): is a callback
used to return the documents with their last change generation
to the target replica.
:return: None
"""
changes_to_return = self.changes_to_return
# return docs, including conflicts
changed_doc_ids = [doc_id for doc_id, _, _ in changes_to_return]
self._trace('before get_docs')
docs = self._db.get_docs(
changed_doc_ids, check_for_conflicts=False, include_deleted=True)
docs_by_gen = izip(
docs, (gen for _, gen, _ in changes_to_return),
(trans_id for _, _, trans_id in changes_to_return))
_outgoing_trace = [] # for tests
for doc, gen, trans_id in docs_by_gen:
return_doc_cb(doc, gen, trans_id)
_outgoing_trace.append((doc.doc_id, doc.rev))
# for tests
self._db._last_exchange_log['return'] = {
'docs': _outgoing_trace,
'last_gen': self.new_gen}
开发者ID:leapcode,项目名称:soledad,代码行数:29,代码来源:sync.py
示例9: unpack
def unpack(self, buff):
"""
Unpack the given binary buffer into the fields. The result
is a dictionary mapping field names to values.
"""
args = struct.unpack_from(self._fmt, buff[:self._size])
return dict(izip(self._names, args))
开发者ID:bsipocz,项目名称:pyasdf,代码行数:7,代码来源:util.py
示例10: eval_model_to_fit
def eval_model_to_fit(self, modelfuncs):
total_model = []
for func, data in izip(modelfuncs, self.datasets):
total_model.append(data.eval_model_to_fit(func))
return numpy.concatenate(total_model)
开发者ID:DougBurke,项目名称:sherpa,代码行数:7,代码来源:data.py
示例11: azip
def azip(*iterables, **kwargs):
"""Move `axis` (default -1) to the front of ndarrays in `iterables`."""
from six.moves import map as imap, zip as izip
return izip(*(
imap(kwargs.get('func', unmask),
np.rollaxis(i, kwargs.get('axis', -1), kwargs.get('start', 0)))
if isinstance(i, np.ndarray) else i for i in iterables))
开发者ID:pbiczo,项目名称:vimconfig,代码行数:7,代码来源:indexing.py
示例12: _parse_set_weight_values
def _parse_set_weight_values(argvish):
new_cmd_format, opts, args = validate_args(argvish)
# We'll either parse the all-in-one-string format or the
# --options format,
# but not both. If both are specified, raise an error.
try:
devs = []
if not new_cmd_format:
if len(args) % 2 != 0:
print(Commands.set_weight.__doc__.strip())
exit(EXIT_ERROR)
devs_and_weights = izip(islice(argvish, 0, len(argvish), 2),
islice(argvish, 1, len(argvish), 2))
for devstr, weightstr in devs_and_weights:
devs.extend(builder.search_devs(
parse_search_value(devstr)) or [])
weight = float(weightstr)
_set_weight_values(devs, weight)
else:
if len(args) != 1:
print(Commands.set_weight.__doc__.strip())
exit(EXIT_ERROR)
devs.extend(builder.search_devs(
parse_search_values_from_opts(opts)) or [])
weight = float(args[0])
_set_weight_values(devs, weight)
except ValueError as e:
print(e)
exit(EXIT_ERROR)
开发者ID:BjoernT,项目名称:swift,代码行数:33,代码来源:ringbuilder.py
示例13: set_arrays
def set_arrays(filename, args, fields=None, ascii=True, clobber=False):
if os.path.isfile(filename) and not clobber:
raise IOErr("filefound", filename)
if not numpy.iterable(args) or len(args) == 0:
raise IOErr('noarrayswrite')
if not numpy.iterable(args[0]):
raise IOErr('noarrayswrite')
size = len(args[0])
for arg in args:
if not numpy.iterable(arg):
raise IOErr('noarrayswrite')
elif len(arg) != size:
raise IOErr('arraysnoteq')
if ascii and '[' not in filename and ']' not in filename:
filename += "[opt kernel=text/simple]"
tbl = pycrates.TABLECrate()
if fields is None:
fields = ['col%i' % (ii + 1) for ii in range(len(args))]
if len(args) != len(fields):
raise IOErr('toomanycols', str(len(fields)), str(len(args)))
for val, name in izip(args, fields):
_set_column(tbl, name, val)
pycrates.write_file(tbl, filename, clobber=True)
close_crate_dataset(tbl.get_dataset())
开发者ID:DougBurke,项目名称:sherpa,代码行数:34,代码来源:crates_backend.py
示例14: multiupdate_metadata
def multiupdate_metadata(self, keys, metadatas):
""" Update the metadata for a collection of keys.
Where supported by an implementation, this should perform the whole
collection of sets as a single transaction.
Like zip() if keys and metadatas have different lengths, then any excess
values in the longer list should be silently ignored.
Parameters
----------
keys : iterable of strings
The keys for the resources in the key-value store. Each key is a
unique identifier for a resource within the key-value store.
metadatas : iterable of dicts
An iterator that provides the metadata dictionaries for the
corresponding keys.
Events
------
StoreSetEvent :
On successful completion of a transaction, a StoreSetEvent should be
emitted with the key & metadata for each key that was set.
"""
with self.transaction('Updating metadata for '+', '.join('"%s"' % key for key in keys)):
for key, metadata in izip(keys, metadatas):
self.update_metadata(key, metadata)
开发者ID:enthought,项目名称:encore,代码行数:28,代码来源:abstract_store.py
示例15: par_at_boundary
def par_at_boundary( low, val, high, tol ):
for par_min, par_val, par_max in izip( low, val, high ):
if sao_fcmp( par_val, par_min, tol ) == 0:
return True
if sao_fcmp( par_val, par_max, tol ) == 0:
return True
return False
开发者ID:mirca,项目名称:sherpa,代码行数:7,代码来源:optfcts.py
示例16: calc
def calc(self, p, arglist):
vals = []
for model, args in izip(self.models, arglist):
# FIXME: we're not using p here (and therefore assuming that the
# parameter values have already been updated to match the contents
# of p)
vals.append(model(*args))
return sum(vals)
开发者ID:mirca,项目名称:sherpa,代码行数:8,代码来源:model.py
示例17: populate_connectors
def populate_connectors(chunkIDs, chunks, cs, connectors):
# Build up edges via the connectors
for c in cs:
# c is (treenode_id, connector_id, relation_id, confidence)
for chunkID, chunk in izip(chunkIDs, chunks):
if c[0] in chunk:
connectors[c[1]][c[2]].append((chunkID, c[3]))
break
开发者ID:davidhildebrand,项目名称:CATMAID,代码行数:8,代码来源:graph2.py
示例18: _yield_text_from_framed_data
def _yield_text_from_framed_data(framed_data, parse=lambda x: x):
parts = [parse(x) for x in framed_data.split(BOUNDARY)]
for text_length, text in izip(parts[1::2], parts[2::2]):
if text_length != str(len(text)):
warning = 'invalid declared length=%s for packet_text=%s' % (
text_length, text)
_log.warn('[packet error] %s', warning)
continue
yield text
开发者ID:astronouth7303,项目名称:socketIO-client,代码行数:9,代码来源:transports.py
示例19: __str__
def __str__(self):
"""
Return a listing of the attributes listed in self._fields and,
if present, self._extra_fields.
"""
fields = self._fields + getattr(self, '_extra_fields', ())
fdict = dict(izip(fields, [getattr(self, f) for f in fields]))
return print_fields(fields, fdict)
开发者ID:DougBurke,项目名称:sherpa,代码行数:9,代码来源:data.py
示例20: calc
def calc(self, p, x, xhi=None, *args, **kwargs):
pha = self.pha
user_grid = False
try:
if self._check_for_user_grid(x, xhi):
user_grid = True
self._startup_user_grid(x, xhi)
# Slow
if self.table is None:
# again, fit() never comes in here b/c it calls startup()
src = self.source
vals = []
for model, args in izip(self.models, self.grid):
elo, ehi = lo, hi = args
if pha.units == 'wavelength':
lo = DataPHA._hc / ehi
hi = DataPHA._hc / elo
vals.append(model(src(lo, hi)))
self.orders = vals
# Fast
else:
xlo, xhi = self.elo, self.ehi
if pha.units == 'wavelength':
xlo, xhi = self.lo, self.hi
src = self.source(xlo, xhi) # hi-res grid of all ARF grids
# Fold summed intervals through the associated response.
self.orders = \
[model(sum_intervals(src, interval[0], interval[1]))
for model, interval in izip(self.models, self.table)]
vals = sum(self.orders)
if self.mask is not None:
vals = vals[self.mask]
finally:
if user_grid:
self._teardown_user_grid()
return vals
开发者ID:mirca,项目名称:sherpa,代码行数:44,代码来源:instrument.py
注:本文中的six.moves.izip函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论