本文整理汇总了Python中math.abs方法的典型用法代码示例。如果您正苦于以下问题:Python math.abs方法的具体用法?Python math.abs怎么用?Python math.abs使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类math
的用法示例。
在下文中一共展示了math.abs方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: distance
# 需要导入模块: import math [as 别名]
# 或者: from math import abs [as 别名]
def distance(self, pointA, pointB):
return math.abs(pointA - pointB)
示例2: load_params
# 需要导入模块: import math [as 别名]
# 或者: from math import abs [as 别名]
def load_params(self):
path = str(self.load_path.with_suffix('.json').resolve())
log.info('[loading parameters from {}]'.format(path))
with open(path, 'r', encoding='utf8') as fp:
params = json.load(fp)
for p in self.GRAPH_PARAMS:
if self.opt.get(p) != params.get(p):
if p in ('kb_embedding_control_sum') and \
(math.abs(self.opt.get(p, 0.) - params.get(p, 0.)) < 1e-3):
continue
raise ConfigError("`{}` parameter must be equal to saved model"
" parameter value `{}`, but is equal to `{}`"
.format(p, params.get(p), self.opt.get(p)))
示例3: next_sample
# 需要导入模块: import math [as 别名]
# 或者: from math import abs [as 别名]
def next_sample(self):
"""Helper function for reading in next sample."""
#set total batch size, for example, 1800, and maximum size for each people, for example 45
if self.seq is not None:
while True:
if self.cur >= len(self.seq):
raise StopIteration
idx = self.seq[self.cur]
self.cur += 1
if self.imgrec is not None:
s = self.imgrec.read_idx(idx)
header, img = recordio.unpack(s)
label = header.label
if self.output_c2c:
count = self.idx2flag[idx]
if self.output_c2c==1:
v = np.random.uniform(0.4, 0.5)
elif self.output_c2c==2:
v = np.random.uniform(0.4, 0.5)
if count>=self.output_c2c:
v = np.random.uniform(0.3, 0.4)
elif self.output_c2c==3:
v = (9.5 - math.log(2.0+count))/10.0
v = min(max(v, 0.3), 0.5)
elif self.output_c2c==4:
mu = 0.0
sigma = 0.1
mrange = [0.4,0.5]
v = numpy.random.normal(mu, sigma)
v = math.abs(v)*-1.0+mrange[1]
v = max(v, mrange[0])
elif self.output_c2c==5:
v = np.random.uniform(0.41, 0.51)
if count>=175:
v = np.random.uniform(0.37, 0.47)
elif self.output_c2c==6:
v = np.random.uniform(0.41, 0.51)
if count>=175:
v = np.random.uniform(0.38, 0.48)
else:
assert False
label = [label, v]
else:
if not isinstance(label, numbers.Number):
label = label[0]
return label, img, None, None
else:
label, fname, bbox, landmark = self.imglist[idx]
return label, self.read_image(fname), bbox, landmark
else:
s = self.imgrec.read()
if s is None:
raise StopIteration
header, img = recordio.unpack(s)
return header.label, img, None, None