mathutils -数学函数

此模块在Python的内置基础上提供了有用的数学函数 math 模块。

class boltons.mathutils.Bits(val=0, len_=None)[源代码]

不变的位串或位数组对象。以布尔形式提供对位的列表访问,以及按位掩码和移位运算符。位还可以方便地在许多不同的有用表示法之间进行转换:

  • 字节--适用于序列化原始二进制数据

  • Int--适合递增(例如,尝试所有可能的值)

  • 布尔列表--适用于迭代或将其视为标志

  • 十六进制/二进制字符串--有利于人类阅读

as_bin()[源代码]
as_bytes()[源代码]
as_hex()[源代码]
as_int()[源代码]
as_list()[源代码]
classmethod from_bin(bin)[源代码]
classmethod from_bytes(bytes_)[源代码]
classmethod from_hex(hex)[源代码]
classmethod from_int(int_, len_=None)[源代码]
classmethod from_list(list_)[源代码]
len
val

可选的舍入函数

boltons.mathutils.clamp(x, lower=-inf, upper=inf)[源代码]

将值限制在给定范围内。

参数:
  • x (int or float) -- 要夹紧的编号。

  • lower (int or float) -- X的最小值。

  • upper (int or float) -- X的最大值。

返回值保证在 lowerupper 。整型、浮点型和其他类似类型可以混合使用。

>>> clamp(1.0, 0, 5)
1.0
>>> clamp(-1.0, 0, 5)
0
>>> clamp(101.0, 0, 5)
5
>>> clamp(123, upper=5)
5

类似于 numpy's clip 功能。

boltons.mathutils.ceil(x, options=None)[源代码]

归还…的天花板 x 。如果 options 设置,则返回最小整数或浮点数 options 它大于或等于 x

参数:
  • x (int or float) -- 要测试的编号。

  • options (iterable) -- 可选的可迭代任意数字(整型或浮点型)。

>>> VALID_CABLE_CSA = [1.5, 2.5, 4, 6, 10, 25, 35, 50]
>>> ceil(3.5, options=VALID_CABLE_CSA)
4
>>> ceil(4, options=VALID_CABLE_CSA)
4
boltons.mathutils.floor(x, options=None)[源代码]

归还……的发言权 x 。如果 options ,则返回最大的整数或浮点数 options 小于或等于 x

参数:
  • x (int or float) -- 要测试的编号。

  • options (iterable) -- 可选的可迭代任意数字(整型或浮点型)。

>>> VALID_CABLE_CSA = [1.5, 2.5, 4, 6, 10, 25, 35, 50]
>>> floor(3.5, options=VALID_CABLE_CSA)
2.5
>>> floor(2.5, options=VALID_CABLE_CSA)
2.5

注: ceil()floor() 函数基于 this example 从中使用 bisect 标准库中的模块。请参考以下内容 StackOverflow Answer 有关此方法的性能影响的更多信息。