本文整理汇总了Python中operator.xor方法的典型用法代码示例。如果您正苦于以下问题:Python operator.xor方法的具体用法?Python operator.xor怎么用?Python operator.xor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类operator
的用法示例。
在下文中一共展示了operator.xor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_inplace_ops_identity2
# 需要导入模块: import operator [as 别名]
# 或者: from operator import xor [as 别名]
def test_inplace_ops_identity2(self, op):
if compat.PY3 and op == 'div':
return
df = DataFrame({'a': [1., 2., 3.],
'b': [1, 2, 3]})
operand = 2
if op in ('and', 'or', 'xor'):
# cannot use floats for boolean ops
df['a'] = [True, False, True]
df_copy = df.copy()
iop = '__i{}__'.format(op)
op = '__{}__'.format(op)
# no id change and value is correct
getattr(df, iop)(operand)
expected = getattr(df_copy, op)(operand)
assert_frame_equal(df, expected)
expected = id(df)
assert id(df) == expected
示例2: calc_minhashes
# 需要导入模块: import operator [as 别名]
# 或者: from operator import xor [as 别名]
def calc_minhashes(self):
def minhashes_for_shingles(shingles):
def calc_onehash(shingle, seed):
def c4_hash(shingle):
h = struct.unpack('<i',shingle)[0]
return h % ((sys.maxsize + 1) * 2)
if self.sh_type == 'c4':
return operator.xor(c4_hash(shingle), long(seed)) % self.modulo
else:
return operator.xor(compute_positive_hash(shingle), long(seed)) % self.modulo
minhashes = [sys.maxsize for _ in xrange(self.hashes)]
for shingle in shingles:
for hno in xrange(self.hashes):
h_value = calc_onehash(shingle, self.seeds[hno])
minhashes[hno] = min(h_value, minhashes[hno])
return minhashes
##########################################
shingles = self.shingles()
minhashes = minhashes_for_shingles(shingles)
return minhashes
示例3: calc_minhashes
# 需要导入模块: import operator [as 别名]
# 或者: from operator import xor [as 别名]
def calc_minhashes(parsed_text, sh_type, hashes, seeds, modulo):
def minhashes_for_shingles(shingles, sh_type, hashes, seeds, modulo):
def calc_onehash(sh_type, shingle, seed, modulo):
def c4_hash(shingle):
h = struct.unpack('<i',shingle)[0]
return h % ((sys.maxsize + 1) * 2)
if sh_type == 'c4':
return operator.xor(c4_hash(shingle), long(seed)) % modulo
else:
return operator.xor(compute_positive_hash(shingle), long(seed)) % modulo
minhashes = [sys.maxsize for _ in xrange(hashes)]
for shingle in shingles:
for hno in xrange(hashes):
h_value = calc_onehash(sh_type, shingle, seeds[hno], modulo)
minhashes[hno] = min(h_value, minhashes[hno])
return minhashes
shingles = parsed_text.split() if sh_type=='w' else set(_get_list_of_shingles(parsed_text))
minhashes = minhashes_for_shingles(shingles, sh_type, hashes, seeds, modulo)
return minhashes
示例4: zscore
# 需要导入模块: import operator [as 别名]
# 或者: from operator import xor [as 别名]
def zscore(data2d, axis=0):
"""Standardize the mean and variance of the data axis Parameters.
:param data2d: DataFrame to normalize.
:param axis: int, Which axis to normalize across. If 0, normalize across rows,
if 1, normalize across columns. If None, don't change data
:Returns: Normalized DataFrame. Normalized data with a mean of 0 and variance of 1
across the specified axis.
"""
if axis is None:
# normalized to mean and std using entire matrix
# z_scored = (data2d - data2d.values.mean()) / data2d.values.std(ddof=1)
return data2d
assert axis in [0,1]
z_scored = data2d.apply(lambda x: (x-x.mean())/x.std(ddof=1),
axis=operator.xor(1, axis))
return z_scored
示例5: ctr_counter
# 需要导入模块: import operator [as 别名]
# 或者: from operator import xor [as 别名]
def ctr_counter(nonce, f, start = 0):
"""
Return an infinite iterator that starts at `start` and iterates by 1 over
integers between 0 and 2^64 - 1 cyclically, returning on each iteration the
result of combining each number with `nonce` using function `f`.
`nonce` should be an random 64-bit integer that is used to make the counter
unique.
`f` should be a function that takes two 64-bit integers, the first being the
`nonce`, and combines the two in a lossless manner (i.e. xor, addition, etc.)
The returned value should be a 64-bit integer.
`start` should be a number less than 2^64.
"""
for n in range(start, 2**64):
yield f(nonce, n)
while True:
for n in range(0, 2**64):
yield f(nonce, n)
示例6: _validateChecksum
# 需要导入模块: import operator [as 别名]
# 或者: from operator import xor [as 别名]
def _validateChecksum(sentence):
"""
Validates the checksum of an NMEA sentence.
@param sentence: The NMEA sentence to check the checksum of.
@type sentence: C{bytes}
@raise ValueError: If the sentence has an invalid checksum.
Simply returns on sentences that either don't have a checksum,
or have a valid checksum.
"""
if sentence[-3:-2] == b'*': # Sentence has a checksum
reference, source = int(sentence[-2:], 16), sentence[1:-3]
computed = reduce(operator.xor, [ord(x) for x in iterbytes(source)])
if computed != reference:
raise base.InvalidChecksum("%02x != %02x" % (computed, reference))
示例7: chain_with_mv
# 需要导入模块: import operator [as 别名]
# 或者: from operator import xor [as 别名]
def chain_with_mv(self):
coords = x, y, z = symbols('x y z', real=True)
ga, ex, ey, ez = Ga.build('e*x|y|z', g=[1, 1, 1], coords=coords)
s = Sdop([(x, Pdop(x)), (y, Pdop(y))])
assert type(ex * s) is Sdop
assert type(s * ex) is Mv
# type should be preserved even when the result is 0
assert type(ex * Sdop([])) is Sdop
assert type(Sdop([]) * ex) is Mv
# As discussed with brombo, these operations are not well defined - if
# you need them, you should be using `Dop` not `Sdop`.
for op in [operator.xor, operator.or_, operator.lt, operator.gt]:
with pytest.raises(TypeError):
op(ex, s)
with pytest.raises(TypeError):
op(s, ex)
示例8: test_multiply
# 需要导入模块: import operator [as 别名]
# 或者: from operator import xor [as 别名]
def test_multiply(self):
coords = x, y, z = symbols('x y z', real=True)
ga, ex, ey, ez = Ga.build('e*x|y|z', g=[1, 1, 1], coords=coords)
p = Pdop(x)
assert x * p == Sdop([(x, p)])
assert ex * p == Sdop([(ex, p)])
assert p * x == p(x) == S(1)
assert p * ex == p(ex) == S(0)
assert type(p(ex)) is Mv
# These are not defined for consistency with Sdop
for op in [operator.xor, operator.or_, operator.lt, operator.gt]:
with pytest.raises(TypeError):
op(ex, p)
with pytest.raises(TypeError):
op(p, ex)
示例9: binary_back_substitute
# 需要导入模块: import operator [as 别名]
# 或者: from operator import xor [as 别名]
def binary_back_substitute(W: np.ndarray, s: np.ndarray) -> np.ndarray:
"""
Perform back substitution on a binary system of equations, i.e. it performs Gauss elimination
over the field :math:`GF(2)`. It finds an :math:`\\mathbf{x}` such that
:math:`\\mathbf{\\mathit{W}}\\mathbf{x}=\\mathbf{s}`, where all arithmetic is taken bitwise
and modulo 2.
:param W: A square :math:`n\\times n` matrix of 0s and 1s,
in row-echelon (upper-triangle) form
:param s: An :math:`n\\times 1` vector of 0s and 1s
:return: The :math:`n\\times 1` vector of 0s and 1s that solves the above
system of equations.
"""
# iterate backwards, starting from second to last row for back-substitution
m = np.copy(s)
n = len(s)
for row_num in range(n - 2, -1, -1):
row = W[row_num]
for col_num in range(row_num + 1, n):
if row[col_num] == 1:
m[row_num] = xor(s[row_num], s[col_num])
return m[::-1]
示例10: calc_structured_append_parity
# 需要导入模块: import operator [as 别名]
# 或者: from operator import xor [as 别名]
def calc_structured_append_parity(content):
"""\
Calculates the parity data for the Structured Append mode.
:param str content: The content.
:rtype: int
"""
if not isinstance(content, str_type):
content = str(content)
try:
data = content.encode('iso-8859-1')
except UnicodeError:
try:
data = content.encode('shift-jis')
except (LookupError, UnicodeError):
data = content.encode('utf-8')
if _PY2:
data = (ord(c) for c in data)
return reduce(xor, data)
示例11: __hash__
# 需要导入模块: import operator [as 别名]
# 或者: from operator import xor [as 别名]
def __hash__(self):
return reduce(operator.xor, map(hash, (type(self), self.msg)))
示例12: reduceXor
# 需要导入模块: import operator [as 别名]
# 或者: from operator import xor [as 别名]
def reduceXor(bv):
""" Return reduction xor of all bits in bv """
return reduce(operator.xor, [b for b in bv])
示例13: testXor
# 需要导入模块: import operator [as 别名]
# 或者: from operator import xor [as 别名]
def testXor(self):
self.binaryCheck(operator.xor)
示例14: _xor
# 需要导入模块: import operator [as 别名]
# 或者: from operator import xor [as 别名]
def _xor(a: bool, b: bool) -> Tuple[bool]:
return op.xor(a, b),
示例15: __init__
# 需要导入模块: import operator [as 别名]
# 或者: from operator import xor [as 别名]
def __init__(self, left: CriteriaType, right: CriteriaType):
super().__init__(left, right, operator.xor, "^")