本文整理汇总了Python中numpy.bitwise_or函数的典型用法代码示例。如果您正苦于以下问题:Python bitwise_or函数的具体用法?Python bitwise_or怎么用?Python bitwise_or使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了bitwise_or函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: simulatestep
def simulatestep(ps, pm, pv, teilchenort, teilchenmobil, number, vel):
zzv = np.random.random(number)
zzv2 = zzv < ps
zzv3 = zzv < pm
#print "ss"
# print teilchen, number
#zzvVel = np.random.randint(-1,2, size=number)
# zzvVel2 = np.random.random(number)
#zzvVel3 = (zzvVel2 < pv) * zzvVel
#print zzvVel
#berechne neuen Zustand für die Teilchen# bin mobil, wenn
# vorher mobil und es bleibe (zzv3, pm)
# oder: war nicht mobil und bleibe nicht (invertiert zu oder)
mobilneu = np.bitwise_or(np.bitwise_and(teilchenmobil, zzv3),(np.invert(np.bitwise_or(teilchenmobil, zzv2))))
#vel = vel + zzvVel3 * mobilneu
#vel = vel * mobilneu
#print vel
#np.clip(vel, 0, 12, vel)
#print "vel, ss", vel
# wenn mobil, addiere 1 zum Ort
teilchenortneu = teilchenort + vel*mobilneu
return teilchenortneu, mobilneu, vel
示例2: _combine_masks
def _combine_masks(self):
"""Combine multiple mask planes.
Sets the detected mask bit if any image has a detection,
and sets other bits only if set in all images.
Returns
-------
np.ndarray
The combined mask plane.
"""
mask_arr = (exp.getMaskedImage().getMask() for exp in self.exposures)
detected_mask = None
mask_use = None
for mask in mask_arr:
mask_vals = mask.getArray()
if mask_use is None:
mask_use = mask_vals
else:
mask_use = np.bitwise_and(mask_use, mask_vals)
detected_bit = mask.getPlaneBitMask('DETECTED')
if detected_mask is None:
detected_mask = mask_vals & detected_bit
else:
detected_mask = np.bitwise_or(detected_mask, (mask_vals & detected_bit))
mask_vals_return = np.bitwise_or(mask_use, detected_mask)
return mask_vals_return
示例3: place_ship
def place_ship(self, position, length, orientation):
"""
Return None if ship cannot be placed
"""
ship = None
if orientation == 'H':
zeros = np.zeros(self.width * self.height, dtype='int8')
if (position[0] + length) > self.width:
return None
for i in range(length):
zeros[position[1] * self.width + position[0]+i] = 1
if np.all(np.bitwise_and(self._layout, zeros) == 0):
self._layout = np.bitwise_or(self._layout, zeros)
ship = Ship(position, length, orientation)
elif orientation == 'V':
zeros = np.zeros(self.width * self.height, dtype='int8')
if (position[1] + length) > self.height:
return None
for i in range(length):
zeros[(position[1] + i) * self.width + position[0]] = 1
if np.all(np.bitwise_and(self._layout, zeros) == 0):
self._layout = np.bitwise_or(self._layout, zeros)
ship = Ship(position, length, orientation)
if ship:
self._ships.append(ship)
return ship
示例4: filter
def filter(mask, cube, header, clipMethod, threshold, rmsMode, fluxRange, verbose):
err.message("Running threshold finder.")
# Sanity checks of user input
err.ensure(
clipMethod in {"absolute", "relative"},
"Threshold finder failed. Illegal clip method: '" + str(clipMethod) + "'.")
err.ensure(
rmsMode in {"std", "mad", "gauss", "negative"},
"Threshold finder failed. Illegal RMS mode: '" + str(rmsMode) + "'.")
err.ensure(
fluxRange in {"positive", "negative", "all"},
"Threshold finder failed. Illegal flux range: '" + str(fluxRange) + "'.")
# Scale threshold by RMS if requested
if clipMethod == "relative":
threshold *= GetRMS(cube, rmsMode=rmsMode, fluxRange=fluxRange, zoomx=1, zoomy=1, zoomz=1, verbose=verbose)
# Print some information and check sign of threshold
err.message(" Using threshold of " + str(threshold) + ".")
err.ensure(threshold >= 0.0, "Threshold finder failed. Threshold value is negative.")
# Run the threshold finder, setting bit 1 of the mask for |cube| >= |threshold|:
np.bitwise_or(mask, np.greater_equal(np.absolute(cube), threshold), out=mask)
return
示例5: replace_vals
def replace_vals(filename, replace, delim=','):
'''
Replace the values in filename with specified values in replace_values
Parameters
----------
filename : string
Will be read into a rec array
replace_values : tuple
First object is value to replace and second object is what to replace
it with
'''
data = csv2rec(filename, delimiter=delim, missing=replace[0])
for nm in data.dtype.names:
try:
# Missing float
isNaN = (np.isnan(data[nm]))
except:
isNaN = np.zeros(len(data[nm]), dtype=bool)
isBlank = np.array([it == '' for it in data[nm]])
isMinusOne = (data[nm] == -1)# Missing int
# Missing other
isNone = np.array([i == None for i in data[nm]])
ind = np.bitwise_or(isNaN, isBlank)
ind = np.bitwise_or(ind, isMinusOne)
ind = np.bitwise_or(ind, isNone)
data[nm][ind] = replace[1]
return data
示例6: reset_bad_gain
def reset_bad_gain(pdq, gain):
"""
For pixels in the gain array that are either non-positive or NaN, reset the
the corresponding pixels in the pixel DQ array to NO_GAIN_VALUE and
DO_NOT_USE so that they will be ignored.
Parameters
----------
pdq : int, 2D array
pixel dq array of input model
gain : float32, 2D array
gain array from reference file
Returns
-------
pdq : int, 2D array
pixleldq array of input model, reset to NO_GAIN_VALUE and DO_NOT_USE
for pixels in the gain array that are either non-positive or NaN.
"""
wh_g = np.where( gain <= 0.)
if len(wh_g[0]) > 0:
pdq[wh_g] = np.bitwise_or( pdq[wh_g], dqflags.pixel['NO_GAIN_VALUE'] )
pdq[wh_g] = np.bitwise_or( pdq[wh_g], dqflags.pixel['DO_NOT_USE'] )
wh_g = np.where( np.isnan( gain ))
if len(wh_g[0]) > 0:
pdq[wh_g] = np.bitwise_or( pdq[wh_g], dqflags.pixel['NO_GAIN_VALUE'] )
pdq[wh_g] = np.bitwise_or( pdq[wh_g], dqflags.pixel['DO_NOT_USE'] )
return pdq
示例7: read_ports
def read_ports(self):
key = psychopy.event.getKeys(keyList=['1','2','3','k'])
ports = np.asarray([False,False,False])
if key:
if not key[0] in self._key_pressed: self._key_pressed.append(key[0])
if 'k' in self._key_pressed and '1' in self._key_pressed:
ports = np.bitwise_or(ports,[True,False,False])
psychopy.event.clearEvents()
print(self._key_pressed)
self._key_pressed.remove('k')
self._key_pressed.remove('1')
if 'k' in self._key_pressed and '2' in self._key_pressed:
ports = np.bitwise_or(ports,[False,True,False])
psychopy.event.clearEvents()
print(self._key_pressed)
self._key_pressed.remove('k')
self._key_pressed.remove('2')
if 'k' in self._key_pressed and '3' in self._key_pressed:
ports = np.bitwise_or(ports,[False,False,True])
psychopy.event.clearEvents()
print(self._key_pressed)
self._key_pressed.remove('k')
self._key_pressed.remove('3')
return self.get_ports()[ports]
示例8: __invertibleToRGB
def __invertibleToRGB(self, rgbVarr, varrIdx, colorLutStruct):
'''
Decode an RGB image rendered in INVERTIBLE_LUT mode. The image encodes
float values as colors, so the RGB value is first decoded into its
represented float value and then the color table is applied.
'''
w0 = np.left_shift(
rgbVarr[varrIdx[0], varrIdx[1], 0].astype(np.uint32), 16)
w1 = np.left_shift(
rgbVarr[varrIdx[0], varrIdx[1], 1].astype(np.uint32), 8)
w2 = rgbVarr[varrIdx[0], varrIdx[1], 2]
value = np.bitwise_or(w0, w1)
value = np.bitwise_or(value, w2)
value = np.subtract(value.astype(np.int32), 1)
normalized_val = np.divide(value.astype(float), 0xFFFFFE)
# Map float value to color lut (use a histogram to support non-uniform
# colormaps (fetch bin indices))
colorLut = colorLutStruct.lut
bins = colorLutStruct.adjustedBins
idx = np.digitize(normalized_val, bins)
idx = np.subtract(idx, 1)
valueImage = np.zeros([rgbVarr.shape[0], rgbVarr.shape[1]],
dtype=np.uint32)
valueImage[varrIdx[0], varrIdx[1]] = idx
return colorLut[valueImage]
示例9: jaccard_distance
def jaccard_distance(u, v):
"""return jaccard distance"""
u = numpy.asarray(u)
v = numpy.asarray(v)
return (numpy.double(numpy.bitwise_and((u != v),
numpy.bitwise_or(u != 0, v != 0)).sum())
/ numpy.double(numpy.bitwise_or(u != 0, v != 0).sum()))
示例10: pattern_distance_jaccard
def pattern_distance_jaccard(a, b):
"""
Computes a distance measure for two binary patterns based on their
Jaccard-Needham distance, defined as
.. math::
d_J(a,b) = 1 - J(a,b) = \\frac{|a \\cup b| - |a \\cap b|}{|a \\cup b|}.
The similarity measure takes values on the closed interval [0, 1],
where a value of 1 is attained for disjoint, i.e. maximally dissimilar
patterns a and b and a value of 0 for the case of :math:`a=b`.
Parameters
----------
a : list or array, int or bool
Input pattern
b : list or array, int or bool
Input pattern
Returns
-------
dist : double
Jaccard distance between `a` and `b`.
"""
# Note: code taken from scipy. Duplicated as only numpy references wanted for base functionality
a = np.atleast_1d(a).astype(bool)
b = np.atleast_1d(b).astype(bool)
dist = (np.double(np.bitwise_and((a != b), np.bitwise_or(a != 0, b != 0)).sum())
/ np.double(np.bitwise_or(a != 0, b != 0).sum()))
return dist
示例11: partBy2
def partBy2(x):
x = np.bitwise_and(x, 0x1f00000000ffff)
x = np.bitwise_and(np.bitwise_or(x, np.left_shift(x, 32)), 0x1f00000000ffff)
x = np.bitwise_and(np.bitwise_or(x, np.left_shift(x, 16)), 0x1f0000ff0000ff)
x = np.bitwise_and(np.bitwise_or(x, np.left_shift(x, 8)), 0x100f00f00f00f00f)
x = np.bitwise_and(np.bitwise_or(x, np.left_shift(x, 4)), 0x10c30c30c30c30c3)
x = np.bitwise_and(np.bitwise_or(x, np.left_shift(x, 2)), 0x1249249249249249)
return x
示例12: mas_combining4
def mas_combining4(row):
rows = ['DER_mass_MMC','DER_mass_vis','DER_mass_transverse_met_lep']
frame = row[rows[0]] + row[rows[1]] + row[rows[2]]
mask = np.bitwise_or(row[rows[0]]==-999, row[rows[1]]==-999.)
mask = np.bitwise_or(mask, row[rows[1]]==-999.)
frame[mask] = -999.
frame.name = 'MNew_mc4'
return frame
示例13: get_keyv
def get_keyv(iarr, level):
i1, i2, i3 = (v.astype("int64") for v in iarr)
i1 = spread_bitsv(i1, level)
i2 = spread_bitsv(i2, level) << 1
i3 = spread_bitsv(i3, level) << 2
np.bitwise_or(i1, i2, i1)
np.bitwise_or(i1, i3, i1)
return i1
示例14: __call__
def __call__(self):
if hasattr(self.ctx.params, 'cleaner') and self.ctx.params.cleaner != "None":
#load module
mod = importlib.import_module(self.ctx.params.cleaner)
rfi_mask_vx, rfi_mask_vy = mod.rm_rfi(self.ctx)
self.ctx.tod_vx.mask = np.bitwise_or(self.ctx.tod_vx.mask, rfi_mask_vx)
self.ctx.tod_vy.mask = np.bitwise_or(self.ctx.tod_vy.mask, rfi_mask_vy)
示例15: colRowIsOnSciencePixelList
def colRowIsOnSciencePixelList(self, col, row, padding=DEFAULT_PADDING):
"""similar to colRowIsOnSciencePixelList() but takes lists as input"""
out = np.ones(len(col), dtype=bool)
col_arr = np.array(col)
row_arr = np.array(row)
mask = np.bitwise_or(col_arr < 12. - padding, col_arr > 1111 + padding)
out[mask] = False
mask = np.bitwise_or(row_arr < 20. - padding, row_arr > 1043 + padding)
out[mask] = False
return out