本文整理匯總了Python中numpy.bool8方法的典型用法代碼示例。如果您正苦於以下問題:Python numpy.bool8方法的具體用法?Python numpy.bool8怎麽用?Python numpy.bool8使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類numpy
的用法示例。
在下文中一共展示了numpy.bool8方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: testTBX
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import bool8 [as 別名]
def testTBX(self):
config = {
"a": 2,
"b": [1, 2],
"c": {
"c": {
"D": 123
}
},
"d": np.int64(1),
"e": np.bool8(True)
}
t = Trial(evaluated_params=config, trial_id="tbx")
logger = TBXLogger(config=config, logdir=self.test_dir, trial=t)
logger.on_result(result(0, 4))
logger.on_result(result(1, 4))
logger.on_result(result(2, 4, score=[1, 2, 3], hello={"world": 1}))
logger.close()
示例2: initial
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import bool8 [as 別名]
def initial(self):
""" initial part of the transmission loss module
"""
settings = LisSettings.instance()
option = settings.options
if option['TransLoss']:
TransArea = loadmap('TransArea')
self.var.TransSub = loadmap('TransSub')
# downstream area taking into account for transmission loss
self.var.UpAreaTrans = loadmap('UpAreaTrans')
# upstream area
self.var.UpTrans = np.where(self.var.UpAreaTrans >= TransArea,np.bool8(1),np.bool8(0))
# Downstream taking into accound for transmission loss
# if upstream area (the total one) is bigger than a threshold us
# transmission loss
self.var.TransPower1 = loadmap('TransPower1')
self.var.TransPower2 = 1.0 / self.var.TransPower1
# transmission loss function
maskinfo = MaskInfo.instance()
self.var.TransCum = maskinfo.in_zero()
# Cumulative transmission loss
# self.var.TransLossM3Dt = maskinfo.in_zero()
# substep amount of transmission loss
示例3: _get_mask
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import bool8 [as 別名]
def _get_mask(image, mask):
if mask is None:
mask = True
mask_type = _get_dtype(mask).type
if isinstance(mask, (numpy.ndarray, dask.array.Array)):
if mask.shape != image.shape:
raise RuntimeError("`mask` must have the same shape as `image`.")
if not issubclass(mask_type, numpy.bool8):
mask = (mask != 0)
elif issubclass(mask_type, numpy.bool8):
mask = bool(mask)
else:
raise TypeError("`mask` must be a Boolean or an array.")
return mask
示例4: test_bool_types
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import bool8 [as 別名]
def test_bool_types(self):
_skip_if_no_xlrd()
for np_type in (np.bool8, np.bool_):
with ensure_clean(self.ext) as path:
# Test np.bool values read come back as float.
frame = (DataFrame([1, 0, True, False], dtype=np_type))
frame.to_excel(path, 'test1')
reader = ExcelFile(path)
recons = reader.parse('test1').astype(np_type)
tm.assert_frame_equal(frame, recons)
示例5: write_dig_port_stream
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import bool8 [as 別名]
def write_dig_port_stream(channel, samples, rate, timeout=1.0):
'''
Output a binary waveform
Input:
channel - channels to output data to
samples - a 2d numpy array of booleans, 2nd index is the channel
rate - sample rate in Hz
'''
taskHandle = TaskHandle(0)
try:
CHK(nidaq.DAQmxCreateTask("", ctypes.byref(taskHandle)))
CHK(nidaq.DAQmxCreateDOChan(taskHandle, channel, '', DAQmx_Val_ChanForAllLines))
nwritten = int32(0)
vals = numpy.array(samples, numpy.bool8)
if (vals.ndim == 1):
nSamples = 1
else:
nSamples = vals.shape[0]
# DAQmxSetSampClkSrc(taskHandle, "")
CHK(nidaq.DAQmxCfgSampClkTiming(taskHandle, "", float64(rate), DAQmx_Val_Rising, DAQmx_Val_FiniteSamps, uInt64(nSamples)))
nbytes = int32(0)
CHK(nidaq.DAQmxGetWriteDigitalLinesBytesPerChan(taskHandle, ctypes.byref(nbytes)))
CHK(nidaq.DAQmxWriteDigitalLines(taskHandle, int32(nSamples), int32(1),
float64(1.0), int32(DAQmx_Val_GroupByChannel), vals.ctypes.data, ctypes.byref(nwritten), None))
CHK(nidaq.DAQmxStartTask(taskHandle))
except Exception, e:
logging.error('NI DAQ call failed: %s', str(e))
示例6: eval_query_top
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import bool8 [as 別名]
def eval_query_top(self, query_idx, scores, k=(1,5,10,20,50,100)):
""" Evaluates top-k for a given query.
"""
if not self.labels: raise NotImplementedError()
q_label = self.get_query_groundtruth(query_idx, 'label')
correct = np.bool8([l==q_label for l in self.labels])
correct = correct[(-scores).argsort()]
return {k_:float(correct[:k_].any()) for k_ in k if k_<len(correct)}
示例7: _get_structure
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import bool8 [as 別名]
def _get_structure(image, structure):
# Create square connectivity as default
if structure is None:
structure = scipy.ndimage.generate_binary_structure(image.ndim, 1)
elif isinstance(structure, (numpy.ndarray, dask.array.Array)):
if structure.ndim != image.ndim:
raise RuntimeError(
"`structure` must have the same rank as `image`."
)
if not issubclass(structure.dtype.type, numpy.bool8):
structure = (structure != 0)
else:
raise TypeError("`structure` must be an array.")
return structure
示例8: test_bool_types
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import bool8 [as 別名]
def test_bool_types(self):
_skip_if_no_xlrd()
for np_type in (np.bool8, np.bool_):
with ensure_clean(self.ext) as path:
# Test np.bool values read come back as float.
frame = (DataFrame([1, 0, True, False], dtype=np_type))
frame.to_excel(path, 'test1')
reader = ExcelFile(path)
recons = read_excel(reader, 'test1').astype(np_type)
tm.assert_frame_equal(frame, recons)
示例9: tukeyhsd
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import bool8 [as 別名]
def tukeyhsd(self, alpha=0.05):
"""Tukey's range test to compare means of all pairs of groups
Parameters
----------
alpha : float, optional
Value of FWER at which to calculate HSD.
Returns
-------
results : TukeyHSDResults instance
A results class containing relevant data and some post-hoc
calculations
"""
self.groupstats = GroupsStats(
np.column_stack([self.data, self.groupintlab]),
useranks=False)
gmeans = self.groupstats.groupmean
gnobs = self.groupstats.groupnobs #var_ = self.groupstats.groupvarwithin() #possibly an error in varcorrection in this case
var_ = np.var(self.groupstats.groupdemean(), ddof=len(gmeans))
#res contains: 0:(idx1, idx2), 1:reject, 2:meandiffs, 3: std_pairs, 4:confint, 5:q_crit,
#6:df_total, 7:reject2
res = tukeyhsd(gmeans, gnobs, var_, df=None, alpha=alpha, q_crit=None)
resarr = np.array(lzip(self.groupsunique[res[0][0]], self.groupsunique[res[0][1]],
np.round(res[2],4),
np.round(res[4][:, 0],4),
np.round(res[4][:, 1],4),
res[1]),
dtype=[('group1', object),
('group2', object),
('meandiff',float),
('lower',float),
('upper',float),
('reject', np.bool8)])
results_table = SimpleTable(resarr, headers=resarr.dtype.names)
results_table.title = 'Multiple Comparison of Means - Tukey HSD,' + \
'FWER=%4.2f' % alpha
return TukeyHSDResults(self, results_table, res[5], res[1], res[2],
res[3], res[4], res[6], res[7], var_)
示例10: tau_reduction
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import bool8 [as 別名]
def tau_reduction(ms, rate, n_per_decade):
"""Reduce the number of taus to maximum of n per decade (Helper function)
takes in a tau list and reduces the number of taus to a maximum amount per
decade. This is only useful if more than the "decade" and "octave" but
less than the "all" taus are wanted. E.g. to show certain features of
the data one might want 100 points per decade.
NOTE: The algorithm is slightly inaccurate for ms under n_per_decade, and
will also remove some points in this range, which is usually fine.
Typical use would be something like:
(data,m,taus)=tau_generator(data,rate,taus="all")
(m,taus)=tau_reduction(m,rate,n_per_decade)
Parameters
----------
ms: array of integers
List of m values (assumed to be an "all" list) to remove points from.
rate: float
Sample rate of data in Hz. Time interval between measurements
is 1/rate seconds. Used to convert to taus.
n_per_decade: int
Number of ms/taus to keep per decade.
Returns
-------
m: np.array
Reduced list of m values
taus: np.array
Reduced list of tau values
"""
ms = np.int64(ms)
keep = np.bool8(np.rint(n_per_decade*np.log10(ms[1:])) -
np.rint(n_per_decade*np.log10(ms[:-1])))
# Adjust ms size to fit above-defined mask
ms = ms[:-1]
assert len(ms) == len(keep)
ms = ms[keep]
taus = ms/float(rate)
return ms, taus
示例11: _parse_feature_value
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import bool8 [as 別名]
def _parse_feature_value(self, value):
""" Checks if value fits the feature type. If not it tries to fix it or raise an error
:raises: ValueError
"""
if isinstance(value, FeatureIO):
return value
if not hasattr(self, 'ndim'): # Because of serialization/deserialization during multiprocessing
return value
if self.ndim:
if not isinstance(value, np.ndarray):
raise ValueError('{} feature has to be a numpy array'.format(self.feature_type))
if value.ndim != self.ndim:
raise ValueError('Numpy array of {} feature has to have {} '
'dimension{}'.format(self.feature_type, self.ndim, 's' if self.ndim > 1 else ''))
if self.feature_type.is_discrete():
if not issubclass(value.dtype.type, (np.integer, np.bool, np.bool_, np.bool8)):
msg = '{} is a discrete feature type therefore dtype of data should be a subtype of ' \
'numpy.integer or numpy.bool, found type {}. In the future an error will be raised because' \
'of this'.format(self.feature_type, value.dtype.type)
warnings.warn(msg, DeprecationWarning, stacklevel=3)
# raise ValueError('{} is a discrete feature type therefore dtype of data has to be a subtype of '
# 'numpy.integer or numpy.bool, found type {}'.format(self.feature_type,
# value.dtype.type))
# This checking is disabled for now
# else:
# if not issubclass(value.dtype.type, (np.floating, np.float)):
# raise ValueError('{} is a floating feature type therefore dtype of data has to be a subtype of '
# 'numpy.floating or numpy.float, found type {}'.format(self.feature_type,
# value.dtype.type))
return value
if self.is_vector:
if isinstance(value, gpd.GeoSeries):
value = gpd.GeoDataFrame(dict(geometry=value), crs=value.crs)
if isinstance(value, gpd.GeoDataFrame):
if self.feature_type is FeatureType.VECTOR:
if FeatureType.TIMESTAMP.value.upper() not in value:
raise ValueError("{} feature has to contain a column 'TIMESTAMP' with "
"timestamps".format(self.feature_type))
return value
raise ValueError('{} feature works with data of type {}, parsing data type {} is not supported'
'given'.format(self.feature_type, gpd.GeoDataFrame.__name__, type(value)))
return value