當前位置: 首頁>>代碼示例>>Python>>正文


Python math.modf方法代碼示例

本文整理匯總了Python中math.modf方法的典型用法代碼示例。如果您正苦於以下問題:Python math.modf方法的具體用法?Python math.modf怎麽用?Python math.modf使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在math的用法示例。


在下文中一共展示了math.modf方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _get_bytes_from_float

# 需要導入模塊: import math [as 別名]
# 或者: from math import modf [as 別名]
def _get_bytes_from_float(memstr, shift, mem_unit_len):
    try:
        if mem_unit_len == 0:
            memnum = float(memstr)
        else:
            memnum = float(memstr[:-mem_unit_len])
    except ValueError:
        return memstr

    if memstr == '0':
        return int(0)
    f, i = math.modf(memnum)
    num = 1 << shift
    totalmem = (i * num) + (f * num)
    return int(totalmem)

# Used in top command output 
開發者ID:aerospike,項目名稱:aerospike-admin,代碼行數:19,代碼來源:sys_section_parser.py

示例2: testModf

# 需要導入模塊: import math [as 別名]
# 或者: from math import modf [as 別名]
def testModf(self):
        self.assertRaises(TypeError, math.modf)

        def testmodf(name, result, expected):
            (v1, v2), (e1, e2) = result, expected
            if abs(v1-e1) > eps or abs(v2-e2):
                self.fail('%s returned %r, expected %r'%\
                          (name, (v1,v2), (e1,e2)))

        testmodf('modf(1.5)', math.modf(1.5), (0.5, 1.0))
        testmodf('modf(-1.5)', math.modf(-1.5), (-0.5, -1.0))

        self.assertEqual(math.modf(INF), (0.0, INF))
        self.assertEqual(math.modf(NINF), (-0.0, NINF))

        modf_nan = math.modf(NAN)
        self.assertTrue(math.isnan(modf_nan[0]))
        self.assertTrue(math.isnan(modf_nan[1])) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:20,代碼來源:test_math.py

示例3: _encode_val

# 需要導入模塊: import math [as 別名]
# 或者: from math import modf [as 別名]
def _encode_val(value):
        """
            Encode a tick value(open or high or low, etc) as 2 RBG pixels.
            One pixel for interger section and other pixel for fractional section.
        """
        fract, inte = math.modf(value)
        fract = str(int(fract*1000000))
        inte = str(int(inte))
        for i in range(0, 6-len(inte)):
            inte = "0" + inte
        for i in range(0, 6-len(fract)):
            fract = "0" + fract
        pix1 = (int(inte[:2]) + 100,
                int(inte[2:4]) + 100,
                int(inte[4:]) + 100)
        pix2 = (int(fract[:2]) + 100,
                int(fract[2:4]) + 100,
                int(fract[4:]) + 100)
        return [pix1, pix2] 
開發者ID:rrguardo,項目名稱:market_predictor_cnn,代碼行數:21,代碼來源:models.py

示例4: _get_use_and_withhold_idxs_for_filepath

# 需要導入模塊: import math [as 別名]
# 或者: from math import modf [as 別名]
def _get_use_and_withhold_idxs_for_filepath(self, N_samples_in_filepath, 
			start_idx_for_filepath,  train_pct_for_filepath, seed):
		"""
		
		Given characteristics for a filepath (# samples, training pct, and starting idx relative to the corpus),
		uses random selection to return train and test (corpus-based) indices.

		Arguments:
			N_samples_in_filepath: Int 
			start_idx_for_filepath: Int 
			train_pct_for_filepath: Float. 
			seed: Int
				Sets random seed. 
		"""
		np.random.seed(seed=seed)
		permuted_row_idxs=np.random.permutation(N_samples_in_filepath)
		samples_to_use_in_filepath_as_float=train_pct_for_filepath*N_samples_in_filepath
		decimal_part, int_part = math.modf(samples_to_use_in_filepath_as_float)
		last_train_idx_in_this_file=int(int_part)+np.random.binomial(n=1, p=decimal_part) #important if only one sample per file 
		train_indices = permuted_row_idxs[:last_train_idx_in_this_file]+start_idx_for_filepath		
		test_indices = permuted_row_idxs[last_train_idx_in_this_file:]+start_idx_for_filepath		
		return train_indices, test_indices 
開發者ID:cylance,項目名稱:winapi-deobfuscation,代碼行數:24,代碼來源:cut.py

示例5: match_length

# 需要導入模塊: import math [as 別名]
# 或者: from math import modf [as 別名]
def match_length(noise,sr,desired_length):
    noise2 = np.array([])
    final_noiselength = sr*desired_length
    original_noiselength = len(noise)
    frac, int_len = math.modf(final_noiselength/original_noiselength)
    for i in range(int(int_len)):
        noise2 = np.append(noise2,noise)
    if frac:
        max_index = int(original_noiselength*frac)
        end_index = len(noise) - max_index
        rand_start = random.randrange(0,end_index)
        noise2 = np.append(noise2,noise[rand_start:rand_start+max_index])
    if len(noise2) != final_noiselength:
        diff = int(final_noiselength - len(noise2))
        if diff < 0:
            noise2 = noise2[:diff]
        else:
            noise2 = np.append(noise2,np.zeros(diff,))
    return(noise2) 
開發者ID:a-n-rose,項目名稱:Build-CNN-or-LSTM-or-CNNLSTM-with-speech-features,代碼行數:21,代碼來源:prep_noise.py

示例6: _fromtimestamp

# 需要導入模塊: import math [as 別名]
# 或者: from math import modf [as 別名]
def _fromtimestamp(cls, t, utc, tz):
        """Construct a datetime from a POSIX timestamp (like time.time()).

        A timezone info object may be passed in as well.
        """
        frac, t = _math.modf(t)
        us = round(frac * 1e6)
        if us >= 1000000:
            t += 1
            us -= 1000000
        elif us < 0:
            t -= 1
            us += 1000000

        converter = _time.gmtime if utc else _time.localtime
        y, m, d, hh, mm, ss, weekday, jday, dst = converter(t)
        ss = min(ss, 59)    # clamp out leap seconds if the platform has them
        return cls(y, m, d, hh, mm, ss, us, tz) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:20,代碼來源:datetime.py

示例7: testModf

# 需要導入模塊: import math [as 別名]
# 或者: from math import modf [as 別名]
def testModf(self):
        self.assertRaises(TypeError, math.modf)

        def testmodf(name, result, expected):
            (v1, v2), (e1, e2) = result, expected
            if abs(v1-e1) > eps or abs(v2-e2):
                self.fail('%s returned %r, expected %r'%\
                          (name, result, expected))

        testmodf('modf(1.5)', math.modf(1.5), (0.5, 1.0))
        testmodf('modf(-1.5)', math.modf(-1.5), (-0.5, -1.0))

        self.assertEqual(math.modf(INF), (0.0, INF))
        self.assertEqual(math.modf(NINF), (-0.0, NINF))

        modf_nan = math.modf(NAN)
        self.assertTrue(math.isnan(modf_nan[0]))
        self.assertTrue(math.isnan(modf_nan[1])) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:20,代碼來源:test_math.py

示例8: dd2dms

# 需要導入模塊: import math [as 別名]
# 或者: from math import modf [as 別名]
def dd2dms(lat, lon):
        latf, latn = math.modf(lat)
        lonf, lonn = math.modf(lon)
        latd = int(latn)
        latm = int(latf * 60)
        lats = (lat - latd - latm / 60) * 3600.00
        lond = int(lonn)
        lonm = int(lonf * 60)
        lons = (lon - lond - lonm / 60) * 3600.00
        compass = {
            'lat': ('N','S'),
            'lon': ('E','W')
        }
        lat_compass = compass['lat'][0 if latd >= 0 else 1]
        lon_compass = compass['lon'][0 if lond >= 0 else 1]
        return '{}º {}\' {:.2f}" {}, {}º {}\' {:.2f}" {}'.format(abs(latd), 
        	abs(latm), abs(lats), lat_compass, abs(lond), 
        	abs(lonm), abs(lons), lon_compass) 
開發者ID:PacktPublishing,項目名稱:Learning-Geospatial-Analysis-with-Python-Third-Edition,代碼行數:20,代碼來源:B13346_05_10-dd2dms.py

示例9: angle_between

# 需要導入模塊: import math [as 別名]
# 或者: from math import modf [as 別名]
def angle_between(self, other: Any) -> float:
        """
        Returns angle between `self` and `other` in radians. +angle is counter clockwise orientation.

        Args:
            other: :class:`Vector` compatible object

        """
        v2 = self.__class__(other)
        cos_theta = self.dot(v2) / (self.magnitude * v2.magnitude)
        abs_cos_theta = math.fabs(cos_theta)
        if abs_cos_theta > 1.0:
            if abs_cos_theta - 1.0 < 1e-5:
                cos_theta = math.modf(cos_theta)[1]
            else:
                raise ValueError(f'domain error: {cos_theta}')
        return math.acos(cos_theta) 
開發者ID:mozman,項目名稱:ezdxf,代碼行數:19,代碼來源:vector.py

示例10: _get_interp1d_bin_mask

# 需要導入模塊: import math [as 別名]
# 或者: from math import modf [as 別名]
def _get_interp1d_bin_mask(self, seg_xmin, seg_xmax, tscale, num_sample, num_sample_perbin):
        # generate sample mask for a boundary-matching pair
        plen = float(seg_xmax - seg_xmin)
        plen_sample = plen / (num_sample * num_sample_perbin - 1.0)
        total_samples = [
            seg_xmin + plen_sample * ii
            for ii in range(num_sample * num_sample_perbin)
        ]
        p_mask = []
        for idx in range(num_sample):
            bin_samples = total_samples[idx * num_sample_perbin:(idx + 1) * num_sample_perbin]
            bin_vector = np.zeros([tscale])
            for sample in bin_samples:
                sample_upper = math.ceil(sample)
                sample_decimal, sample_down = math.modf(sample)
                if int(sample_down) <= (tscale - 1) and int(sample_down) >= 0:
                    bin_vector[int(sample_down)] += 1 - sample_decimal
                if int(sample_upper) <= (tscale - 1) and int(sample_upper) >= 0:
                    bin_vector[int(sample_upper)] += sample_decimal
            bin_vector = 1.0 / num_sample_perbin * bin_vector
            p_mask.append(bin_vector)
        p_mask = np.stack(p_mask, axis=1)
        return p_mask 
開發者ID:JJBOY,項目名稱:BMN-Boundary-Matching-Network,代碼行數:25,代碼來源:models.py

示例11: _get_interp1d_bin_mask

# 需要導入模塊: import math [as 別名]
# 或者: from math import modf [as 別名]
def _get_interp1d_bin_mask(seg_xmin, seg_xmax, tscale, num_sample,
                           num_sample_perbin):
    """ generate sample mask for a boundary-matching pair """
    plen = float(seg_xmax - seg_xmin)
    plen_sample = plen / (num_sample * num_sample_perbin - 1.0)
    total_samples = [
        seg_xmin + plen_sample * ii
        for ii in range(num_sample * num_sample_perbin)
    ]
    p_mask = []
    for idx in range(num_sample):
        bin_samples = total_samples[idx * num_sample_perbin:(idx + 1) *
                                    num_sample_perbin]
        bin_vector = np.zeros([tscale])
        for sample in bin_samples:
            sample_upper = math.ceil(sample)
            sample_decimal, sample_down = math.modf(sample)
            if int(sample_down) <= (tscale - 1) and int(sample_down) >= 0:
                bin_vector[int(sample_down)] += 1 - sample_decimal
            if int(sample_upper) <= (tscale - 1) and int(sample_upper) >= 0:
                bin_vector[int(sample_upper)] += sample_decimal
        bin_vector = 1.0 / num_sample_perbin * bin_vector
        p_mask.append(bin_vector)
    p_mask = np.stack(p_mask, axis=1)
    return p_mask 
開發者ID:PaddlePaddle,項目名稱:hapi,代碼行數:27,代碼來源:modeling.py

示例12: formatLength

# 需要導入模塊: import math [as 別名]
# 或者: from math import modf [as 別名]
def formatLength(seconds):
    hours, remainder = divmod(seconds, 3600)
    minutes, remseconds = divmod(remainder, 60)
    string = ''
    if hours:
        minformat = '%02d'
    else:
        minformat = '%d'

    if hours or minutes:
        minseconds = '%02d'
    else:
        minseconds = '%d'

    string = ':'.join([y % x for x, y in [(hours, '%d'), (minutes, minformat),
                                          (remseconds, minseconds)] if x])
    miliseconds = math.modf(remseconds)[0]
    if miliseconds:
        string += '{0:.3f}'.format(miliseconds)[1:]
    return string 
開發者ID:antlarr,項目名稱:bard,代碼行數:22,代碼來源:utils.py

示例13: _setv

# 需要導入模塊: import math [as 別名]
# 或者: from math import modf [as 別名]
def _setv(self, off, a):
        self.lock.acquire()
        for v in a:
            (f, i) = math.modf(v)  # split into fraction and integer
            f = int(round(f * 10000))  # we only need 3dp
            (l, h) = self.to_le(int(i))
            self.lcd_data[off] = l
            self.lcd_data[off + 1] = h
            (l, h) = self.to_le(f, v < 0)
            self.lcd_data[off + 2] = l
            self.lcd_data[off + 3] = h
            off += 4
        self.lock.release() 
開發者ID:wolfmanjm,項目名稱:kivy-smoothie-host,代碼行數:15,代碼來源:hb04.py

示例14: convert_timeval

# 需要導入模塊: import math [as 別名]
# 或者: from math import modf [as 別名]
def convert_timeval(seconds_since_epoch):
    """Convert time into C style timeval."""
    frac, whole = math.modf(seconds_since_epoch)
    microseconds = math.floor(frac * 1000000)
    seconds = math.floor(whole)
    return seconds, microseconds 
開發者ID:zeth,項目名稱:inputs,代碼行數:8,代碼來源:inputs.py

示例15: microtime

# 需要導入模塊: import math [as 別名]
# 或者: from math import modf [as 別名]
def microtime(get_as_float=False):
    if get_as_float:
        return time.time()
    else:
        return '%.8f %d' % math.modf(time.time()) 
開發者ID:muYoz,項目名稱:xunfeng_vul_poc,代碼行數:7,代碼來源:DiscuzX1.5X2.5X3_uc_key_getshell.py


注:本文中的math.modf方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。