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


Python numpy.bitwise_xor方法代碼示例

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


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

示例1: gaussian_elimination_mod2

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import bitwise_xor [as 別名]
def gaussian_elimination_mod2(A):
    """
    Gaussian elimination mod2 of A.

    """

    A = _np.array(A, dtype='int')
    m, n = A.shape
    i, j = 0, 0

    while (i < m) and (j < n):
        k = A[i:m, j].argmax() + i
        A[_np.array([i, k]), :] = A[_np.array([k, i]), :]
        aijn = _np.array([A[i, j:]])
        col = _np.array([A[:, j]]).T
        col[i] = 0
        flip = _np.dot(col, aijn)
        A[:, j:] = _np.bitwise_xor(A[:, j:], flip)
        i += 1
        j += 1
    return A 
開發者ID:pyGSTio,項目名稱:pyGSTi,代碼行數:23,代碼來源:matrixmod2.py

示例2: test_NotImplemented_not_returned

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import bitwise_xor [as 別名]
def test_NotImplemented_not_returned(self):
        # See gh-5964 and gh-2091. Some of these functions are not operator
        # related and were fixed for other reasons in the past.
        binary_funcs = [
            np.power, np.add, np.subtract, np.multiply, np.divide,
            np.true_divide, np.floor_divide, np.bitwise_and, np.bitwise_or,
            np.bitwise_xor, np.left_shift, np.right_shift, np.fmax,
            np.fmin, np.fmod, np.hypot, np.logaddexp, np.logaddexp2,
            np.logical_and, np.logical_or, np.logical_xor, np.maximum,
            np.minimum, np.mod,
            np.greater, np.greater_equal, np.less, np.less_equal,
            np.equal, np.not_equal]

        a = np.array('1')
        b = 1
        c = np.array([1., 2.])
        for f in binary_funcs:
            assert_raises(TypeError, f, a, b)
            assert_raises(TypeError, f, c, a) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:21,代碼來源:test_ufunc.py

示例3: test_values

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import bitwise_xor [as 別名]
def test_values(self):
        for dt in self.bitwise_types:
            zeros = np.array([0], dtype=dt)
            ones = np.array([-1], dtype=dt)
            msg = "dt = '%s'" % dt.char

            assert_equal(np.bitwise_not(zeros), ones, err_msg=msg)
            assert_equal(np.bitwise_not(ones), zeros, err_msg=msg)

            assert_equal(np.bitwise_or(zeros, zeros), zeros, err_msg=msg)
            assert_equal(np.bitwise_or(zeros, ones), ones, err_msg=msg)
            assert_equal(np.bitwise_or(ones, zeros), ones, err_msg=msg)
            assert_equal(np.bitwise_or(ones, ones), ones, err_msg=msg)

            assert_equal(np.bitwise_xor(zeros, zeros), zeros, err_msg=msg)
            assert_equal(np.bitwise_xor(zeros, ones), ones, err_msg=msg)
            assert_equal(np.bitwise_xor(ones, zeros), ones, err_msg=msg)
            assert_equal(np.bitwise_xor(ones, ones), zeros, err_msg=msg)

            assert_equal(np.bitwise_and(zeros, zeros), zeros, err_msg=msg)
            assert_equal(np.bitwise_and(zeros, ones), zeros, err_msg=msg)
            assert_equal(np.bitwise_and(ones, zeros), zeros, err_msg=msg)
            assert_equal(np.bitwise_and(ones, ones), ones, err_msg=msg) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:25,代碼來源:test_umath.py

示例4: test_NotImplemented_not_returned

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import bitwise_xor [as 別名]
def test_NotImplemented_not_returned(self):
        # See gh-5964 and gh-2091. Some of these functions are not operator
        # related and were fixed for other reasons in the past.
        binary_funcs = [
            np.power, np.add, np.subtract, np.multiply, np.divide,
            np.true_divide, np.floor_divide, np.bitwise_and, np.bitwise_or,
            np.bitwise_xor, np.left_shift, np.right_shift, np.fmax,
            np.fmin, np.fmod, np.hypot, np.logaddexp, np.logaddexp2,
            np.logical_and, np.logical_or, np.logical_xor, np.maximum,
            np.minimum, np.mod
            ]

        # These functions still return NotImplemented. Will be fixed in
        # future.
        # bad = [np.greater, np.greater_equal, np.less, np.less_equal, np.not_equal]

        a = np.array('1')
        b = 1
        for f in binary_funcs:
            assert_raises(TypeError, f, a, b) 
開發者ID:abhisuri97,項目名稱:auto-alt-text-lambda-api,代碼行數:22,代碼來源:test_ufunc.py

示例5: set_ufunc

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import bitwise_xor [as 別名]
def set_ufunc(self, scalar_op):
        # This is probably a speed up of the implementation
        if isinstance(scalar_op, theano.scalar.basic.Add):
            self.ufunc = numpy.add
        elif isinstance(scalar_op, theano.scalar.basic.Mul):
            self.ufunc = numpy.multiply
        elif isinstance(scalar_op, theano.scalar.basic.Maximum):
            self.ufunc = numpy.maximum
        elif isinstance(scalar_op, theano.scalar.basic.Minimum):
            self.ufunc = numpy.minimum
        elif isinstance(scalar_op, theano.scalar.basic.AND):
            self.ufunc = numpy.bitwise_and
        elif isinstance(scalar_op, theano.scalar.basic.OR):
            self.ufunc = numpy.bitwise_or
        elif isinstance(scalar_op, theano.scalar.basic.XOR):
            self.ufunc = numpy.bitwise_xor
        else:
            self.ufunc = numpy.frompyfunc(scalar_op.impl, 2, 1) 
開發者ID:muhanzhang,項目名稱:D-VAE,代碼行數:20,代碼來源:elemwise.py

示例6: get_unique_wfs

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import bitwise_xor [as 別名]
def get_unique_wfs(n=10000, duration=32, defined_channels=frozenset(['A'])):
    if not hasattr(get_unique_wfs, 'cache'):
        get_unique_wfs.cache = {}

    key = (n, duration)

    if key not in get_unique_wfs.cache:
        h = hash(key)
        base = np.bitwise_xor(np.linspace(-h, h, num=duration + n, dtype=np.int64), h)
        base = base / np.max(np.abs(base))

        get_unique_wfs.cache[key] = [
            DummyWaveform(duration=duration, sample_output=base[idx:idx+duration],
                          defined_channels=defined_channels)
            for idx in range(n)
        ]
    return get_unique_wfs.cache[key] 
開發者ID:qutech,項目名稱:qupulse,代碼行數:19,代碼來源:seqc_tests.py

示例7: _hash_rows

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import bitwise_xor [as 別名]
def _hash_rows(array, mult=1000003, dtype=np.uint64):
    # Code based on python's tupleobject hasing
    # Generate hash
    mult = dtype(mult)
    sorted = np.sort(array, axis=1).astype(dtype)
    hash_array = 0x345678 * np.ones(array.shape[0], dtype=dtype)
    for i in reversed(range(array.shape[1])):
        hash_array = np.bitwise_xor(hash_array, sorted[:, i]) * mult
        mult += dtype(82520 + i + i)
    hash_array += dtype(97531)
    hash_array[hash_array == -1] = -2
    return hash_array 
開發者ID:simnibs,項目名稱:simnibs,代碼行數:14,代碼來源:mesh_io.py

示例8: _colsum

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import bitwise_xor [as 別名]
def _colsum(self, i, j):
        """ Col_i = Col_j * Col_i where '*' is group action"""
        n, s = self.n, self.s
        for p in self.ps:
            p[i] = (p[i] + p[j] + 2 * float(_np.dot(s[:, i].T, _np.dot(self.u, s[:, j])))) % 4
        for k in range(n):
            s[k, i] = s[k, j] ^ s[k, i]
            s[k + n, i] = s[k + n, j] ^ s[k + n, i]
            #TODO: use _np.bitwise_xor or logical_xor here? -- keep it obvious (&slow) for now...
        return 
開發者ID:pyGSTio,項目名稱:pyGSTi,代碼行數:12,代碼來源:stabilizer.py

示例9: test_truth_table_bitwise

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import bitwise_xor [as 別名]
def test_truth_table_bitwise(self):
        arg1 = [False, False, True, True]
        arg2 = [False, True, False, True]

        out = [False, True, True, True]
        assert_equal(np.bitwise_or(arg1, arg2), out)

        out = [False, False, False, True]
        assert_equal(np.bitwise_and(arg1, arg2), out)

        out = [False, True, True, False]
        assert_equal(np.bitwise_xor(arg1, arg2), out) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:14,代碼來源:test_umath.py

示例10: test_types

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import bitwise_xor [as 別名]
def test_types(self):
        for dt in self.bitwise_types:
            zeros = np.array([0], dtype=dt)
            ones = np.array([-1], dtype=dt)
            msg = "dt = '%s'" % dt.char

            assert_(np.bitwise_not(zeros).dtype == dt, msg)
            assert_(np.bitwise_or(zeros, zeros).dtype == dt, msg)
            assert_(np.bitwise_xor(zeros, zeros).dtype == dt, msg)
            assert_(np.bitwise_and(zeros, zeros).dtype == dt, msg) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:12,代碼來源:test_umath.py

示例11: test_identity

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import bitwise_xor [as 別名]
def test_identity(self):
        assert_(np.bitwise_or.identity == 0, 'bitwise_or')
        assert_(np.bitwise_xor.identity == 0, 'bitwise_xor')
        assert_(np.bitwise_and.identity == -1, 'bitwise_and') 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:6,代碼來源:test_umath.py

示例12: hamming_distance

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import bitwise_xor [as 別名]
def hamming_distance(a, b):
  r = (1 << np.arange(8))[:,None]
  return np.count_nonzero((np.bitwise_xor(a,b) & r) != 0) 
開發者ID:geohot,項目名稱:twitchslam,代碼行數:5,代碼來源:helpers.py


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