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


Python operator.xor方法代碼示例

本文整理匯總了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 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:25,代碼來源:test_operators.py

示例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 
開發者ID:singhj,項目名稱:locality-sensitive-hashing,代碼行數:23,代碼來源:blobs.py

示例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 
開發者ID:singhj,項目名稱:locality-sensitive-hashing,代碼行數:23,代碼來源:map_reduce.py

示例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 
開發者ID:zqfang,項目名稱:GSEApy,代碼行數:21,代碼來源:plot.py

示例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) 
開發者ID:cilame,項目名稱:vrequest,代碼行數:22,代碼來源:pyblowfish.py

示例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)) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:19,代碼來源:nmea.py

示例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) 
開發者ID:pygae,項目名稱:galgebra,代碼行數:21,代碼來源:test_differential_ops.py

示例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) 
開發者ID:pygae,項目名稱:galgebra,代碼行數:20,代碼來源:test_differential_ops.py

示例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] 
開發者ID:rigetti,項目名稱:grove,代碼行數:25,代碼來源:utils.py

示例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) 
開發者ID:a4k-openproject,項目名稱:plugin.program.openwizard,代碼行數:21,代碼來源:encoder.py

示例11: __hash__

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import xor [as 別名]
def __hash__(self):
        return reduce(operator.xor, map(hash, (type(self), self.msg))) 
開發者ID:hjimce,項目名稱:Depth-Map-Prediction,代碼行數:4,代碼來源:thutil.py

示例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]) 
開發者ID:myhdl,項目名稱:myhdl,代碼行數:5,代碼來源:rs232_util.py

示例13: testXor

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import xor [as 別名]
def testXor(self):
        self.binaryCheck(operator.xor) 
開發者ID:myhdl,項目名稱:myhdl,代碼行數:4,代碼來源:test_Signal.py

示例14: _xor

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import xor [as 別名]
def _xor(a: bool, b: bool) -> Tuple[bool]:
    return op.xor(a, b), 
開發者ID:erp12,項目名稱:pyshgp,代碼行數:4,代碼來源:logical.py

示例15: __init__

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import xor [as 別名]
def __init__(self, left: CriteriaType, right: CriteriaType):
        super().__init__(left, right, operator.xor, "^") 
開發者ID:tensortrade-org,項目名稱:tensortrade,代碼行數:4,代碼來源:criteria.py


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