本文整理汇总了Python中pyLibrary.maths.Math.abs方法的典型用法代码示例。如果您正苦于以下问题:Python Math.abs方法的具体用法?Python Math.abs怎么用?Python Math.abs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyLibrary.maths.Math
的用法示例。
在下文中一共展示了Math.abs方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: geo_mean
# 需要导入模块: from pyLibrary.maths import Math [as 别名]
# 或者: from pyLibrary.maths.Math import abs [as 别名]
def geo_mean(values):
"""
GIVEN AN ARRAY OF dicts, CALC THE GEO-MEAN ON EACH ATTRIBUTE
"""
agg = Struct()
for d in values:
for k, v in d.items():
if v != 0:
agg[k] = nvl(agg[k], ZeroMoment.new_instance()) + Math.log(Math.abs(v))
return {k: Math.exp(v.stats.mean) for k, v in agg.items()}
示例2: __unicode__
# 需要导入模块: from pyLibrary.maths import Math [as 别名]
# 或者: from pyLibrary.maths.Math import abs [as 别名]
def __unicode__(self):
if not self.milli:
return "zero"
output = ""
rest = (self.milli - (MILLI_VALUES.month * self.month)) # DO NOT INCLUDE THE MONTH'S MILLIS
isNegative = (rest < 0)
rest = Math.abs(rest)
# MILLI
rem = rest % 1000
if rem != 0:
output = "+" + unicode(rem) + "milli" + output
rest = Math.floor(rest / 1000)
# SECOND
rem = rest % 60
if rem != 0:
output = "+" + unicode(rem) + "second" + output
rest = Math.floor(rest / 60)
# MINUTE
rem = rest % 60
if rem != 0:
output = "+" + unicode(rem) + "minute" + output
rest = Math.floor(rest / 60)
# HOUR
rem = rest % 24
if rem != 0:
output = "+" + unicode(rem) + "hour" + output
rest = Math.floor(rest / 24)
# DAY
if (rest < 11 and rest != 7) or rest % 10 == 0:
rem = rest
rest = 0
else:
rem = rest % 7
rest = Math.floor(rest / 7)
if rem != 0:
output = "+" + unicode(rem) + "day" + output
# WEEK
if rest != 0:
output = "+" + unicode(rest) + "week" + output
if isNegative:
output = output.replace("+", "-")
# MONTH AND YEAR
if self.month:
sign = "-" if self.month < 0 else "+"
month = Math.abs(self.month)
if month <= 18 and month != 12:
output = sign + unicode(month) + "month" + output
else:
m = month % 12
if m != 0:
output = sign + unicode(m) + "month" + output
y = Math.floor(month / 12)
output = sign + unicode(y) + "year" + output
if output[0] == "+":
output = output[1::]
if output[0] == '1' and not Math.is_number(output[1]):
output = output[1::]
return output