当前位置: 首页>>代码示例>>Python>>正文


Python math.floor方法代码示例

本文整理汇总了Python中math.floor方法的典型用法代码示例。如果您正苦于以下问题:Python math.floor方法的具体用法?Python math.floor怎么用?Python math.floor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在math的用法示例。


在下文中一共展示了math.floor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: checker

# 需要导入模块: import math [as 别名]
# 或者: from math import floor [as 别名]
def checker(x, y, step):
    x -= (u_width / 2)
    y -= (u_height / 2)
    angle = (step / 10.0)
    s = math.sin(angle)
    c = math.cos(angle)
    xs = x * c - y * s
    ys = x * s + y * c
    xs -= math.sin(step / 200.0) * 40.0
    ys -= math.cos(step / 200.0) * 40.0
    scale = step % 20
    scale /= 20
    scale = (math.sin(step / 50.0) / 8.0) + 0.25
    xs *= scale
    ys *= scale
    xo = abs(xs) - int(abs(xs))
    yo = abs(ys) - int(abs(ys))
    v = 0 if (math.floor(xs) + math.floor(ys)) % 2 else 1 if xo > .1 and yo > .1 else .5
    r, g, b = hue_to_rgb[step % 255]
    return (r * (v * 255), g * (v * 255), b * (v * 255))


# weeee waaaah 
开发者ID:pimoroni,项目名称:unicorn-hat-hd,代码行数:25,代码来源:demo.py

示例2: getValue

# 需要导入模块: import math [as 别名]
# 或者: from math import floor [as 别名]
def getValue(self, settings, e):
        if e.index == 1:
            return _GXCommon.logicalNameToBytes(self.logicalName)
        if e.index == 2:
            return self.value
        if e.index == 3:
            data = GXByteBuffer()
            data.setUInt8(DataType.STRUCTURE)
            data.setUInt8(2)
            _GXCommon.setData(settings, data, DataType.INT8, math.floor(math.log(self.scaler, 10)))
            _GXCommon.setData(settings, data, DataType.ENUM, int(self.unit))
            return data.array()
        if e.index == 4:
            return self.status
        if e.index == 5:
            return self.captureTime
        e.error = ErrorCode.READ_WRITE_DENIED
        return None

    #
    #      Set value of given attribute.
    # 
开发者ID:Gurux,项目名称:Gurux.DLMS.Python,代码行数:24,代码来源:GXDLMSExtendedRegister.py

示例3: getValue

# 需要导入模块: import math [as 别名]
# 或者: from math import floor [as 别名]
def getValue(self, settings, e):
        if e.index == 1:
            return _GXCommon.logicalNameToBytes(self.logicalName)
        if e.index == 2:
            return self.value
        if e.index == 3:
            data = GXByteBuffer()
            data.setUInt8(DataType.STRUCTURE)
            data.setUInt8(2)
            _GXCommon.setData(settings, data, DataType.INT8, math.floor(math.log(self.scaler, 10)))
            _GXCommon.setData(settings, data, DataType.ENUM, int(self.unit))
            return data.array()
        e.error = ErrorCode.READ_WRITE_DENIED
        return None

    #
    # Set value of given attribute.
    #
    #pylint: disable=broad-except 
开发者ID:Gurux,项目名称:Gurux.DLMS.Python,代码行数:21,代码来源:GXDLMSRegister.py

示例4: __init__

# 需要导入模块: import math [as 别名]
# 或者: from math import floor [as 别名]
def __init__(self, name, width, height, model_nm=None, props=None):
        super().__init__(name, width, height, torus=False,
                         model_nm=model_nm, postact=True, props=props)

        self.center_agent = None
        self.set_var_color('0', disp.BLACK)
        self.set_var_color('1', disp.MAGENTA)
        self.set_var_color('2', disp.BLUE)
        self.set_var_color('3', disp.CYAN)
        self.set_var_color('4', disp.RED)
        self.set_var_color('5', disp.YELLOW)
        self.set_var_color('6', disp.GREEN)
        center_x = floor(self.width // 2)
        center_y = floor(self.height // 2)
        print("center = %i, %i" % (center_x, center_y))

        for cell in self:
            (x, y) = cell.coords
            agent = SandAgent("Grainy", "Hold sand", cell)
            self.add_agent(agent, position=False)
            if x == center_x and y == center_y:
                self.center_agent = agent 
开发者ID:gcallah,项目名称:indras_net,代码行数:24,代码来源:sand.py

示例5: step

# 需要导入模块: import math [as 别名]
# 或者: from math import floor [as 别名]
def step(self, amt=1):
        center = float(self._maxLed) / 2
        center_floor = math.floor(center)
        center_ceil = math.ceil(center)

        if self._centerOut:
            self.layout.fill(
                self.palette(self._step), int(center_floor - self._current), int(center_floor - self._current))
            self.layout.fill(
                self.palette(self._step), int(center_ceil + self._current), int(center_ceil + self._current))
        else:
            self.layout.fill(
                self.palette(self._step), int(self._current), int(self._current))
            self.layout.fill(
                self.palette(self._step), int(self._maxLed - self._current), int(self._maxLed - self._current))

        self._step += amt + self._rainbowInc

        if self._current == center_floor:
            self._current = self._minLed
        else:
            self._current += amt 
开发者ID:ManiacalLabs,项目名称:BiblioPixelAnimations,代码行数:24,代码来源:HalvesRainbow.py

示例6: _get_octave

# 需要导入模块: import math [as 别名]
# 或者: from math import floor [as 别名]
def _get_octave(seed, coord):
    x = coord.real
    y = coord.imag

    cellx = math.floor(x)
    celly = math.floor(y)

    value00 = _perlin_random(seed, cellx, celly)
    value10 = _perlin_random(seed, cellx + 1, celly)
    value01 = _perlin_random(seed, cellx, celly + 1)
    value11 = _perlin_random(seed, cellx + 1, celly + 1)

    offsetx = x % 1.0
    offsety = y % 1.0

    value0 = offsetx * value10 + (1 - offsetx) * value00
    value1 = offsetx * value11 + (1 - offsetx) * value01

    result = offsety * value1 + (1 - offsety) * value0

    return result * INV_MAX_VALUE 
开发者ID:ondergetekende,项目名称:python-panavatar,代码行数:23,代码来源:parameters.py

示例7: __init__

# 需要导入模块: import math [as 别名]
# 或者: from math import floor [as 别名]
def __init__(self, seed, octaves=None, detail=None,
                 min_value=0, max_value=1, size=1.0):

        if not octaves:
            octaves = max(1, int(math.floor(math.log(size / detail, 2))))

        scales = [.5 ** o for o in range(octaves)]
        inv_total_scale = 1.0 / sum(scales)

        self.min_value = min_value
        self.max_value = max_value
        self.inv_size = 1.0 / size

        self.octaves = [
            (inv_total_scale * scale,
             1.0 / (inv_total_scale * scale),
             (seed ^ o * 541) & 0x3FFFFFFF)
            for (o, scale)
            in enumerate(scales)] 
开发者ID:ondergetekende,项目名称:python-panavatar,代码行数:21,代码来源:parameters.py

示例8: mouseMoveEvent

# 需要导入模块: import math [as 别名]
# 或者: from math import floor [as 别名]
def mouseMoveEvent(self, event):
        if self.__dragging:
            newPos = self.mapToScene(event.pos())

            graph = self.getGraph()
            if graph.getSnapToGrid() is True:
                gridSize = graph.getGridSize()

                newNodePos = newPos - self._mouseDelta

                snapPosX = math.floor(newNodePos.x() / gridSize) * gridSize;
                snapPosY = math.floor(newNodePos.y() / gridSize) * gridSize;
                snapPos = QtCore.QPointF(snapPosX, snapPosY)

                newPosOffset = snapPos - newNodePos

                newPos = newPos + newPosOffset

            delta = newPos - self._lastDragPoint
            self.__graph.moveSelectedNodes(delta)
            self._lastDragPoint = newPos
            self._nodesMoved = True
        else:
            super(Node, self).mouseMoveEvent(event) 
开发者ID:EricTRocks,项目名称:pyflowgraph,代码行数:26,代码来源:node.py

示例9: grid_batch_images

# 需要导入模块: import math [as 别名]
# 或者: from math import floor [as 别名]
def grid_batch_images(self, images):
        n, h, w, c = images.shape
        a = int(math.floor(np.sqrt(n)))
        # images = (((images - images.min()) * 255) / (images.max() - images.min())).astype(np.uint8)
        images = images.astype(np.uint8)
        images_in_square = np.reshape(images[:a * a], (a, a, h, w, c))
        new_img = np.zeros((h * a, w * a, c), dtype=np.uint8)
        for col_i, col_images in enumerate(images_in_square):
            for row_i, image in enumerate(col_images):
                new_img[col_i * h: (1 + col_i) * h, row_i * w: (1 + row_i) * w] = image
        resolution = self.cfg.resolution
        if self.cfg.resolution != h:
            scale = resolution / h
            new_img = cv2.resize(new_img, None, fx=scale, fy=scale,
                                 interpolation=cv2.INTER_NEAREST)
        return new_img 
开发者ID:preritj,项目名称:progressive_growing_of_GANs,代码行数:18,代码来源:utils.py

示例10: _place

# 需要导入模块: import math [as 别名]
# 或者: from math import floor [as 别名]
def _place(self, p, kind=Cell.unknown):
        if not self.preview:
            self.preview = Cell()
            self.preview.kind = kind
            self.preview.setOpacity(0.4)
            self.addItem(self.preview)
        x, y = convert_pos(p.x(), p.y())
        x = round(x)
        for yy in [round(y), int(math.floor(y - 1e-4)), int(math.ceil(y + 1e-4))]:
            self.preview.coord = (x, yy)
            if not any(isinstance(it, Cell) for it in self.preview.overlapping):
                break
        else:
            self.preview.coord = (round(x), round(y))
        self.preview.upd()
        self.preview._text.setText('') 
开发者ID:oprypin,项目名称:sixcells,代码行数:18,代码来源:editor.py

示例11: get_bbox_target_single_box

# 需要导入模块: import math [as 别名]
# 或者: from math import floor [as 别名]
def get_bbox_target_single_box(single_box, spatial_dim=7, img_w=640., img_h=360., thd=0.5):
    """
    :param single_box: a single box
    :param spatial_dim:
    :param img_w:
    :param img_h:
    :param thd: round thd
    :return:
    """
    top = single_box["top"]
    left = single_box["left"]
    bottom = top + single_box["height"]
    right = left + single_box["width"]

    # map to 224x224 to 7x7
    top = int(math.floor((top * spatial_dim) / img_h + thd))
    bottom = int(math.ceil((bottom * spatial_dim) / img_h - thd))
    left = int(math.floor((left * spatial_dim) / img_w + thd))
    right = int(math.ceil((right * spatial_dim) / img_w - thd))
    gt_att_map = np.zeros([spatial_dim, spatial_dim]).astype(np.float32)
    gt_att_map[top: bottom+1, left:right+1] = 1
    # print(top, bottom, left, right)
    return gt_att_map 
开发者ID:jayleicn,项目名称:TVQAplus,代码行数:25,代码来源:utils.py

示例12: compute_mean_ci

# 需要导入模块: import math [as 别名]
# 或者: from math import floor [as 别名]
def compute_mean_ci(interp_sens, confidence = 0.95):
    sens_mean = np.zeros((interp_sens.shape[1]),dtype = 'float32')
    sens_lb   = np.zeros((interp_sens.shape[1]),dtype = 'float32')
    sens_up   = np.zeros((interp_sens.shape[1]),dtype = 'float32')
    
    Pz = (1.0-confidence)/2.0
    print(interp_sens.shape)
    for i in range(interp_sens.shape[1]):
        # get sorted vector
        vec = interp_sens[:,i]
        vec.sort()

        sens_mean[i] = np.average(vec)
        sens_lb[i] = vec[int(math.floor(Pz*len(vec)))]
        sens_up[i] = vec[int(math.floor((1.0-Pz)*len(vec)))]

    return sens_mean,sens_lb,sens_up 
开发者ID:uci-cbcl,项目名称:DeepLung,代码行数:19,代码来源:noduleCADEvaluationLUNA16.py

示例13: __init__

# 需要导入模块: import math [as 别名]
# 或者: from math import floor [as 别名]
def __init__(self, inplanes, planes, groups, reduction, stride=1,
                 downsample=None, base_width=4):
        super(SEResNeXtBottleneck, self).__init__()
        width = math.floor(planes * (base_width / 64)) * groups
        self.conv1 = nn.Conv2d(inplanes, width, kernel_size=1, bias=False,
                               stride=1)
        self.bn1 = nn.BatchNorm2d(width)
        self.conv2 = nn.Conv2d(width, width, kernel_size=3, stride=stride,
                               padding=1, groups=groups, bias=False)
        self.bn2 = nn.BatchNorm2d(width)
        self.conv3 = nn.Conv2d(width, planes * 4, kernel_size=1, bias=False)
        self.bn3 = nn.BatchNorm2d(planes * 4)
        self.relu = nn.ReLU(inplace=True)
        self.se_module = SEModule(planes * 4, reduction=reduction)
        self.downsample = downsample
        self.stride = stride 
开发者ID:lRomul,项目名称:argus-freesound,代码行数:18,代码来源:senet.py

示例14: __round__

# 需要导入模块: import math [as 别名]
# 或者: from math import floor [as 别名]
def __round__(self, ndigits=None):
        """Will be round(self, ndigits) in 3.0.

        Rounds half toward even.
        """
        if ndigits is None:
            floor, remainder = divmod(self.numerator, self.denominator)
            if remainder * 2 < self.denominator:
                return floor
            elif remainder * 2 > self.denominator:
                return floor + 1
            # Deal with the half case:
            elif floor % 2 == 0:
                return floor
            else:
                return floor + 1
        shift = 10**abs(ndigits)
        # See _operator_fallbacks.forward to check that the results of
        # these operations will always be Fraction and therefore have
        # round().
        if ndigits > 0:
            return Fraction(round(self * shift), shift)
        else:
            return Fraction(round(self / shift) * shift) 
开发者ID:war-and-code,项目名称:jawfish,代码行数:26,代码来源:fractions.py

示例15: getValue

# 需要导入模块: import math [as 别名]
# 或者: from math import floor [as 别名]
def getValue(self, settings, e):
        if e.index == 1:
            ret = _GXCommon.logicalNameToBytes(self.logicalName)
        elif e.index == 2:
            ret = self.currentAverageValue
        elif e.index == 3:
            ret = self.lastAverageValue
        elif e.index == 4:
            data = GXByteBuffer()
            data.setUInt8(DataType.STRUCTURE)
            data.setUInt8(2)
            _GXCommon.setData(settings, data, DataType.INT8, math.floor(math.log(self.scaler, 10)))
            _GXCommon.setData(settings, data, DataType.ENUM, int(self.unit))
            ret = data.array()
        elif e.index == 5:
            ret = self.status
        elif e.index == 6:
            ret = self.captureTime
        elif e.index == 7:
            ret = self.startTimeCurrent
        elif e.index == 8:
            ret = self.period
        elif e.index == 9:
            ret = self.numberOfPeriods
        else:
            e.error = ErrorCode.READ_WRITE_DENIED
        return ret

    #
    # Set value of given attribute.
    # pylint: disable=broad-except 
开发者ID:Gurux,项目名称:Gurux.DLMS.Python,代码行数:33,代码来源:GXDLMSDemandRegister.py


注:本文中的math.floor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。