本文整理汇总了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
示例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)
示例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)
示例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)
示例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)
示例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]
示例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
示例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
示例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)
示例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)
示例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')
示例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)