本文整理匯總了Python中builtins.reversed方法的典型用法代碼示例。如果您正苦於以下問題:Python builtins.reversed方法的具體用法?Python builtins.reversed怎麽用?Python builtins.reversed使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類builtins
的用法示例。
在下文中一共展示了builtins.reversed方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: evaluate_operation
# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import reversed [as 別名]
def evaluate_operation(cls, operation, context, **kwargs):
"""
Evaluate an operation or constant given a context.
"""
try:
if isinstance(operation, Operation):
return operation.evaluate(context, **kwargs)
partial = functools.partial(cls.evaluate_operation, context=context, **kwargs)
if isinstance(operation, tuple):
return tuple(partial(element) for element in operation)
if isinstance(operation, list):
return [partial(element) for element in operation]
if isinstance(operation, dict):
return {partial(key): partial(value) for key, value in operation.items()}
if isinstance(operation, slice):
return slice(*[partial(getattr(operation, attr))
for attr in ['start', 'stop', 'step']])
return operation
except Exception as ex: # pragma: no cover
stack = []
interactive = False
for frame in reversed(operation._stack): # pylint: disable=protected-access
# Do not capture any internal stack traces
if 'pythonflow' in frame.filename:
continue
# Stop tracing at the last interactive cell
if interactive and not frame.filename.startswith('<'):
break # pragma: no cover
interactive = frame.filename.startswith('<')
stack.append(frame)
stack = "".join(traceback.format_list(reversed(stack)))
message = "Failed to evaluate operation `%s` defined at:\n\n%s" % (operation, stack)
raise ex from EvaluationError(message)
示例2: __reversed__
# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import reversed [as 別名]
def __reversed__(self):
return _coconut.reversed(self._xrange)
示例3: _coconut_back_compose
# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import reversed [as 別名]
def _coconut_back_compose(*funcs): return _coconut_forward_compose(*_coconut.reversed(funcs))
示例4: _coconut_back_star_compose
# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import reversed [as 別名]
def _coconut_back_star_compose(*funcs): return _coconut_forward_star_compose(*_coconut.reversed(funcs))
示例5: _coconut_back_dubstar_compose
# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import reversed [as 別名]
def _coconut_back_dubstar_compose(*funcs): return _coconut_forward_dubstar_compose(*_coconut.reversed(funcs))
示例6: __new__
# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import reversed [as 別名]
def __new__(cls, iterable):
if _coconut.isinstance(iterable, _coconut.range):
return iterable[::-1]
if not _coconut.hasattr(iterable, "__reversed__") or _coconut.isinstance(iterable, (_coconut.list, _coconut.tuple)):
return _coconut.object.__new__(cls)
return _coconut.reversed(iterable)
示例7: __repr__
# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import reversed [as 別名]
def __repr__(self):
return "reversed(%r)" % (self.iter,)
示例8: count
# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import reversed [as 別名]
def count(self, elem):
"""Count the number of times elem appears in the reversed iterator."""
return self.iter.count(elem)
示例9: index
# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import reversed [as 別名]
def index(self, elem):
"""Find the index of elem in the reversed iterator."""
return _coconut.len(self.iter) - self.iter.index(elem) - 1
示例10: __iter__
# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import reversed [as 別名]
def __iter__(self):
return _coconut.iter(_coconut.reversed(self.iter))
示例11: reversed
# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import reversed [as 別名]
def reversed(seq):
'''Replacement for the built-in
:func:`reversed() <python:reversed>` function.'''
return builtins.reversed(seq)
示例12: checkDesignMatrix
# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import reversed [as 別名]
def checkDesignMatrix(X):
"""
Parameters
----------
X: a matrix of shape (T, N), where T denotes the number
of samples and N labels the number of features.
If T < N, a warning is issued to the user, and the transpose
of X is considered instead.
Returns:
T: type int
N: type int
transpose_flag: type bool
Specify if the design matrix X should be transposed
in view of having less rows than columns.
"""
try:
assert isinstance(X, (np.ndarray, pd.DataFrame, pd.Series,
MutableSequence, Sequence))
except AssertionError:
raise
sys.exit(1)
X = np.asarray(X, dtype=float)
X = np.atleast_2d(X)
if X.shape[0] < X.shape[1]:
warnings.warn("The Marcenko-Pastur distribution pertains to "
"the empirical covariance matrix of a random matrix X "
"of shape (T, N). It is assumed that the number of "
"samples T is assumed higher than the number of "
"features N. The transpose of the matrix X submitted "
"at input will be considered in the cleaning schemes "
"for the corresponding correlation matrix.", UserWarning)
T, N = reversed(X.shape)
transpose_flag = True
else:
T, N = X.shape
transpose_flag = False
return T, N, transpose_flag