python类around()的实例源码

test_netcdftime.py 文件源码 项目:netcdftime 作者: Unidata 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def test_dayofwk(self):
        "Test computation of dayofwk in the 365_day calendar."

        converter = self.converters["noleap"]

        # Pick the date corresponding to the Julian day of 1.0 to test
        # the transision from positive to negative Julian days.
        julian_day = converter.date2num(datetimex(-4712, 1, 2, 12))

        old_date = converter.num2date(julian_day)
        for delta_year in range(1, 101): # 100 years cover several 7-year cycles
            date = converter.num2date(julian_day - delta_year * 365)

            # test that the day of the week changes by one every year (except
            # for wrapping around every 7 years, of course)
            if date.dayofwk == 6:
                self.assertEqual(old_date.dayofwk, 0)
            else:
                self.assertEqual(old_date.dayofwk - date.dayofwk, 1)

            old_date = date
test_indexing.py 文件源码 项目:PyDataLondon29-EmbarrassinglyParallelDAWithAWSLambda 作者: SignalMedia 项目源码 文件源码 阅读 42 收藏 0 点赞 0 评论 0
def test_reindex_nearest(self):
        s = Series(np.arange(10, dtype='int64'))
        target = [0.1, 0.9, 1.5, 2.0]
        actual = s.reindex(target, method='nearest')
        expected = Series(np.around(target).astype('int64'), target)
        assert_series_equal(expected, actual)

        actual = s.reindex_like(actual, method='nearest')
        assert_series_equal(expected, actual)

        actual = s.reindex_like(actual, method='nearest', tolerance=1)
        assert_series_equal(expected, actual)

        actual = s.reindex(target, method='nearest', tolerance=0.2)
        expected = Series([0, 1, np.nan, 2], target)
        assert_series_equal(expected, actual)
testutils.py 文件源码 项目:PyDataLondon29-EmbarrassinglyParallelDAWithAWSLambda 作者: SignalMedia 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def almost(a, b, decimal=6, fill_value=True):
    """
    Returns True if a and b are equal up to decimal places.

    If fill_value is True, masked values considered equal. Otherwise,
    masked values are considered unequal.

    """
    m = mask_or(getmask(a), getmask(b))
    d1 = filled(a)
    d2 = filled(b)
    if d1.dtype.char == "O" or d2.dtype.char == "O":
        return np.equal(d1, d2).ravel()
    x = filled(masked_array(d1, copy=False, mask=m), fill_value).astype(float_)
    y = filled(masked_array(d2, copy=False, mask=m), 1).astype(float_)
    d = np.around(np.abs(x - y), decimal) <= 10.0 ** (-decimal)
    return d.ravel()
browser.py 文件源码 项目:gcMapExplorer 作者: rjdkmr 项目源码 文件源码 阅读 41 收藏 0 点赞 0 评论 0
def ylimit(self, value):
        """Upper and lower limit of current plot.
        Permanent limits are stored in yScaleSteps, which can be changed by user using range box.

        This is the only function through which plots can be updated.
        """
        if value[0] == value[1]:
            return

        if not self.hiCmapAxis.doNotPlot:
            self._ylimit = [ value[0], value[1] ]

            # Setting yticks based on ylimits, only change yticks when y-limits are changed
            ydiff = value[0] - value[1]
            yticks = np.linspace(self.ylimit[0], self.ylimit[1], 100)

            # Set tick label according to precision
            self.yticksDecimals = gmlib.util.locate_significant_digit_after_decimal(ydiff)
            if self.yticksDecimals > 3:
                self.yticksFormatStyle = 'sci'
                self.yticks = np.around(yticks, decimals=self.yticksDecimals+1)
            else:
                self.yticks = np.around(yticks, decimals=self.yticksDecimals+1)

            self.updatePlot()
acore.py 文件源码 项目:aRMSD 作者: armsd 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def project_radii(radii, spacing, r_min, r_max):
    """ Projects given radii to values between r_min and r_max; good spacing ~ 1000 """

    radii_norm = radii / np.max(radii)  # Normalize radii

    # Determine min and max of array and generate spacing
    radii_to_proj = np.around(np.linspace(np.min(radii_norm), np.max(radii_norm), spacing), 3)
    values_to_proj = np.around(np.linspace(r_min, r_max, spacing), 3)

    # Determine respective array positions
    pos = np.array([np.argmin(np.abs(radii_to_proj -
                                     radii_norm[entry])) for entry in range(len(radii_norm))], dtype=np.int)

    # Determine new radii
    return np.take(values_to_proj, pos)


###############################################################################
# HUNGARIAN (MUNKRES) ALGORITHM - TAKEN FROM SCIPY
###############################################################################
fromnumeric.py 文件源码 项目:aws-lambda-numpy 作者: vitolimandibhrata 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def round_(a, decimals=0, out=None):
    """
    Round an array to the given number of decimals.

    Refer to `around` for full documentation.

    See Also
    --------
    around : equivalent function

    """
    try:
        round = a.round
    except AttributeError:
        return _wrapit(a, 'round', decimals, out)
    return round(decimals, out)
testutils.py 文件源码 项目:aws-lambda-numpy 作者: vitolimandibhrata 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def almost(a, b, decimal=6, fill_value=True):
    """
    Returns True if a and b are equal up to decimal places.

    If fill_value is True, masked values considered equal. Otherwise,
    masked values are considered unequal.

    """
    m = mask_or(getmask(a), getmask(b))
    d1 = filled(a)
    d2 = filled(b)
    if d1.dtype.char == "O" or d2.dtype.char == "O":
        return np.equal(d1, d2).ravel()
    x = filled(masked_array(d1, copy=False, mask=m), fill_value).astype(float_)
    y = filled(masked_array(d2, copy=False, mask=m), 1).astype(float_)
    d = np.around(np.abs(x - y), decimal) <= 10.0 ** (-decimal)
    return d.ravel()
qclib.py 文件源码 项目:quantum-computing 作者: QuantumSystems 项目源码 文件源码 阅读 46 收藏 0 点赞 0 评论 0
def qreport(self, header="State", state=None, visualize=False):
        # This is only a simulator function for debugging. it CANNOT be done on a real Quantum Computer.
        if state == None:
            state = self.sys_state
        print
        print header
        for i in range(len(state)):
            if self.disp_zeros or np.absolute(state[i]) > self.maxerr:
                barlen = 20
                barstr = ""
                if self.visualize or visualize:
                    barstr = "  x"
                    amp = np.absolute(state[i].item(0))*barlen
                    intamp = int(amp)
                    if amp > self.maxerr:
                        barstr = "  |"
                        for b in range(barlen):
                            if b <= intamp:
                                barstr = barstr+"*"
                            else:
                                barstr = barstr + "."
                ststr = ("{:0"+str(self.nqbits)+"b}    ").format(i)
                ampstr = "{:.8f}".format(np.around(state[i].item(0),8))
                print ststr + ampstr + barstr
utils.py 文件源码 项目:TF-FaceLandmarkDetection 作者: mariolew 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def genLandmarkMap(landmarks, shape=[39, 39]):
    '''Generate landmark map according to landmarks.
    Input params:
    landmarks: K x 2 float 
    shape: H x W
    Output:
    landmarkMap: H x W x K binary map. For each H x W
    map, there's only one location nearest to the landmark
    location filled with 1, else 0.'''

    landmarks = landmarks.reshape((-1, 2))
    landmarkMap = np.zeros(shape + [len(landmarks)])
    for (i, landmark) in enumerate(landmarks):
        x = int(np.around(landmark[0] * shape[1]))
        y = int(np.around(landmark[1] * shape[0]))
        landmarkMap[y, x, i] = 1
    return landmarkMap
fromnumeric.py 文件源码 项目:lambda-numba 作者: rlhotovy 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def round_(a, decimals=0, out=None):
    """
    Round an array to the given number of decimals.

    Refer to `around` for full documentation.

    See Also
    --------
    around : equivalent function

    """
    try:
        round = a.round
    except AttributeError:
        return _wrapit(a, 'round', decimals, out)
    return round(decimals, out)
test_all.py 文件源码 项目:ZOO-Attack 作者: huanzhang12 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def show(img, name = "output.png"):
    """
    Show MNSIT digits in the console.
    """
    np.save(name, img)
    fig = np.around((img + 0.5)*255)
    fig = fig.astype(np.uint8).squeeze()
    pic = Image.fromarray(fig)
    # pic.resize((512,512), resample=PIL.Image.BICUBIC)
    pic.save(name)
    remap = "  .*#"+"#"*100
    img = (img.flatten()+.5)*3
    if len(img) != 784: return
    print("START")
    for i in range(28):
        print("".join([remap[int(round(x))] for x in img[i*28:i*28+28]]))


问题


面经


文章

微信
公众号

扫码关注公众号