本文整理匯總了Python中numpy.bitwise_and方法的典型用法代碼示例。如果您正苦於以下問題:Python numpy.bitwise_and方法的具體用法?Python numpy.bitwise_and怎麽用?Python numpy.bitwise_and使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類numpy
的用法示例。
在下文中一共展示了numpy.bitwise_and方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_NotImplemented_not_returned
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import bitwise_and [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)
示例2: test_values
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import bitwise_and [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)
示例3: _freq_vector
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import bitwise_and [as 別名]
def _freq_vector(f, b, typ='lp'):
"""
Returns a frequency modulated vector for filtering
:param f: frequency vector, uniform and monotonic
:param b: 2 bounds array
:return: amplitude modulated frequency vector
"""
filc = ((f <= b[0]).astype(float) +
np.bitwise_and(f > b[0], f < b[1]).astype(float) *
(0.5 * (1 + np.sin(np.pi * (f - ((b[0] + b[1]) / 2)) /
(b[0] - b[1])))))
if typ == 'hp':
return 1 - filc
elif typ == 'lp':
return filc
示例4: test_NotImplemented_not_returned
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import bitwise_and [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_and [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: agent_start
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import bitwise_and [as 別名]
def agent_start(self, observation):
# Get intensity from current observation array
tmp = np.bitwise_and(np.asarray(observation.intArray[128:]).reshape([210, 160]), 0b0001111) # Get Intensity from the observation
obs_array = (spm.imresize(tmp, (110, 84)))[110-84-8:110-8, :] # Scaling
# Initialize State
self.state = np.zeros((4, 84, 84), dtype=np.uint8)
self.state[0] = obs_array
state_ = cuda.to_gpu(np.asanyarray(self.state.reshape(1, 4, 84, 84), dtype=np.float32))
# Generate an Action e-greedy
returnAction = Action()
action, Q_now = self.DQN.e_greedy(state_, self.epsilon)
returnAction.intArray = [action]
# Update for next step
self.lastAction = copy.deepcopy(returnAction)
self.last_state = self.state.copy()
self.last_observation = obs_array
return returnAction
示例7: agent_start
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import bitwise_and [as 別名]
def agent_start(self, observation):
# Preprocess
tmp = np.bitwise_and(np.asarray(observation.intArray[128:]).reshape([210, 160]), 0b0001111) # Get Intensity from the observation
obs_array = (spm.imresize(tmp, (110, 84)))[110-84-8:110-8, :] # Scaling
# Initialize State
self.state = np.zeros((4, 84, 84), dtype=np.uint8)
self.state[0] = obs_array
state_ = cuda.to_gpu(np.asanyarray(self.state.reshape(1, 4, 84, 84), dtype=np.float32))
# Generate an Action e-greedy
returnAction = Action()
action, Q_now = self.DQN.e_greedy(state_, self.epsilon)
returnAction.intArray = [action]
# Update for next step
self.lastAction = copy.deepcopy(returnAction)
self.last_state = self.state.copy()
self.last_observation = obs_array
return returnAction
示例8: guess_wfnsym
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import bitwise_and [as 別名]
def guess_wfnsym(self, norb, nelec, fcivec=None, orbsym=None, wfnsym=None,
**kwargs):
if orbsym is None:
orbsym = self.orbsym
if fcivec is None:
wfnsym = direct_spin1_symm._id_wfnsym(self, norb, nelec, orbsym, wfnsym)
elif wfnsym is None:
strsa, strsb = getattr(fcivec, '_strs', self._strs)
if isinstance(fcivec, numpy.ndarray) and fcivec.ndim <= 2:
wfnsym = addons._guess_wfnsym(fcivec, strsa, strsb, orbsym)
else:
wfnsym = [addons._guess_wfnsym(c, strsa, strsb, orbsym)
for c in fcivec]
if any(wfnsym[0] != x for x in wfnsym):
warnings.warn('Different wfnsym %s found in different CI vecotrs' % wfnsym)
wfnsym = wfnsym[0]
else:
strsa, strsb = getattr(fcivec, '_strs', self._strs)
na, nb = strsa.size, strsb.size
airreps = numpy.zeros(na, dtype=numpy.int32)
birreps = numpy.zeros(nb, dtype=numpy.int32)
for i, ir in enumerate(orbsym):
airreps[numpy.bitwise_and(strsa, 1<<i) > 0] ^= ir
birreps[numpy.bitwise_and(strsb, 1<<i) > 0] ^= ir
wfnsym = direct_spin1_symm._id_wfnsym(self, norb, nelec, orbsym, wfnsym)
mask = (airreps.reshape(-1,1) ^ birreps) == wfnsym
if isinstance(fcivec, numpy.ndarray) and fcivec.ndim <= 2:
fcivec = [fcivec]
if all(abs(c.reshape(na, nb)[mask]).max() < 1e-5 for c in fcivec):
raise RuntimeError('Input wfnsym is not consistent with fcivec coefficients')
verbose = kwargs.get('verbose', None)
log = logger.new_logger(self, verbose)
log.debug('Guessing CI wfn symmetry = %s', wfnsym)
return wfnsym
示例9: _symmetrize_wfn
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import bitwise_and [as 別名]
def _symmetrize_wfn(ci, strsa, strsb, orbsym, wfnsym=0):
ci = ci.reshape(strsa.size,strsb.size)
airreps = numpy.zeros(strsa.size, dtype=numpy.int32)
birreps = numpy.zeros(strsb.size, dtype=numpy.int32)
for i, ir in enumerate(orbsym):
airreps[numpy.bitwise_and(strsa, 1<<i) > 0] ^= ir
birreps[numpy.bitwise_and(strsb, 1<<i) > 0] ^= ir
mask = (airreps.reshape(-1,1) ^ birreps) == wfnsym
ci1 = numpy.zeros_like(ci)
ci1[mask] = ci[mask]
ci1 *= 1/numpy.linalg.norm(ci1)
return ci1
示例10: _gen_strs_irrep
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import bitwise_and [as 別名]
def _gen_strs_irrep(strs, orbsym):
orbsym = numpy.asarray(orbsym) % 10
irreps = numpy.zeros(len(strs), dtype=numpy.int32)
if isinstance(strs, cistring.OIndexList):
nocc = strs.shape[1]
for i in range(nocc):
irreps ^= orbsym[strs[:,i]]
else:
for i, ir in enumerate(orbsym):
irreps[numpy.bitwise_and(strs, 1<<i) > 0] ^= ir
return irreps
示例11: exprsco_to_rawsco
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import bitwise_and [as 別名]
def exprsco_to_rawsco(exprsco, clock=1789773.):
rate, nsamps, exprsco = exprsco
m = exprsco[:, :3, 0]
m_zero = np.where(m == 0)
m = m.astype(np.float32)
f = 440 * np.power(2, ((m - 69) / 12))
f_p, f_tr = f[:, :2], f[:, 2:]
t_p = np.round((clock / (16 * f_p)) - 1)
t_tr = np.round((clock / (32 * f_tr)) - 1)
t = np.concatenate([t_p, t_tr], axis=1)
t = t.astype(np.uint16)
t[m_zero] = 0
th = np.right_shift(np.bitwise_and(t, 0b11100000000), 8)
tl = np.bitwise_and(t, 0b00011111111)
rawsco = np.zeros((exprsco.shape[0], 4, 4), dtype=np.uint8)
rawsco[:, :, 2:] = exprsco[:, :, 1:]
rawsco[:, :3, 0] = th
rawsco[:, :3, 1] = tl
rawsco[:, 3, 1:] = exprsco[:, 3, :]
return (clock, rate, nsamps, rawsco)
示例12: test_truth_table_bitwise
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import bitwise_and [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)
示例13: test_types
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import bitwise_and [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)
示例14: test_identity
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import bitwise_and [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')
示例15: __init__
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import bitwise_and [as 別名]
def __init__(self, image, label, regions, dxyz, iorigin=[0, 0, 0],
dims2xyz=[0, 1, 2], xyz2dims=[0, 1, 2]):
"""
self.image: image volume (ap, ml, dv)
self.label: label volume (ap, ml, dv)
self.bc: atlas.BrainCoordinate object
self.regions: atlas.BrainRegions object
self.top: 2d np array (ap, ml) containing the z-coordinate (m) of the surface of the brain
self.dims2xyz and self.zyz2dims: map image axis order to xyz coordinates order
"""
self.image = image
self.label = label
self.regions = regions
self.dims2xyz = dims2xyz
self.xyz2dims = xyz2dims
assert(np.all(self.dims2xyz[self.xyz2dims] == np.array([0, 1, 2])))
assert(np.all(self.xyz2dims[self.dims2xyz] == np.array([0, 1, 2])))
# create the coordinate transform object that maps volume indices to real world coordinates
nxyz = np.array(self.image.shape)[self.dims2xyz]
bc = BrainCoordinates(nxyz=nxyz, xyz0=(0, 0, 0), dxyz=dxyz)
self.bc = BrainCoordinates(nxyz=nxyz, xyz0=- bc.i2xyz(iorigin), dxyz=dxyz)
"""
Get the volume top surface
"""
l0 = self.label == 0
s = np.zeros(self.label.shape[:2])
s[np.all(l0, axis=2)] = np.nan
iz = 0
# not very elegant, but fast enough for our purposes
while True:
if iz >= l0.shape[2]:
break
inds = np.bitwise_and(s == 0, ~l0[:, :, iz])
s[inds] = iz
iz += 1
self.top = self.bc.i2z(s)