本文整理匯總了Python中sys.float_info方法的典型用法代碼示例。如果您正苦於以下問題:Python sys.float_info方法的具體用法?Python sys.float_info怎麽用?Python sys.float_info使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類sys
的用法示例。
在下文中一共展示了sys.float_info方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: get_float
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import float_info [as 別名]
def get_float(min_size=None, max_size=None):
"""
return a random float
sames as the random method but automatically sets min and max
:param min_size: float, the minimum float size you want
:param max_size: float, the maximum float size you want
:returns: float, a random value between min_size and max_size
"""
float_info = sys.float_info
if min_size is None:
min_size = float_info.min
if max_size is None:
max_size = float_info.max
return random.uniform(min_size, max_size)
示例2: rank
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import float_info [as 別名]
def rank(self):
ws = defaultdict(float)
outSum = defaultdict(float)
wsdef = 1.0 / (len(self.graph) or 1.0)
for n, out in self.graph.items():
ws[n] = wsdef
outSum[n] = sum((e[2] for e in out), 0.0)
# this line for build stable iteration
sorted_keys = sorted(self.graph.keys())
for x in xrange(10): # 10 iters
for n in sorted_keys:
s = 0
for e in self.graph[n]:
s += e[2] / outSum[e[1]] * ws[e[1]]
ws[n] = (1 - self.d) + self.d * s
(min_rank, max_rank) = (sys.float_info[0], sys.float_info[3])
for w in itervalues(ws):
if w < min_rank:
min_rank = w
if w > max_rank:
max_rank = w
for n, w in ws.items():
# to unify the weights, don't *100.
ws[n] = (w - min_rank / 10.0) / (max_rank - min_rank / 10.0)
return ws
示例3: test_float_roundtrip
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import float_info [as 別名]
def test_float_roundtrip(self):
info = sys.float_info
inf = float("inf")
nan = float("nan")
self.assertEqual(1.0, serialize.load(serialize.dump(1.0)))
self.assertEqual(-1.0, serialize.load(serialize.dump(-1.0)))
self.assertEqual(info.min, serialize.load(serialize.dump(info.min)))
self.assertEqual(info.max, serialize.load(serialize.dump(info.max)))
self.assertEqual(inf, serialize.load(serialize.dump(inf)))
self.assertEqual(-inf, serialize.load(serialize.dump(-inf)))
self.assertTrue(math.isnan(serialize.load(serialize.dump(nan))))
示例4: sysmis
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import float_info [as 別名]
def sysmis(self):
"""This function returns the IBM SPSS Statistics system-missing
value ($SYSMIS) for the host system (also called 'NA' in other
systems)."""
try:
sysmis = -1 * sys.float_info[0] # Python 2.6 and higher.
except AttributeError:
self.spssio.spssSysmisVal.restype = c_float
sysmis = self.spssio.spssSysmisVal()
return sysmis
示例5: test_float_info_tuple
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import float_info [as 別名]
def test_float_info_tuple(self):
self.assertEqual(tuple(sys.float_info), sys.float_info)
示例6: rank
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import float_info [as 別名]
def rank(self):
ws = defaultdict(float)
outSum = defaultdict(float)
wsdef = 1.0 / (len(self.graph) or 1.0)
for n, out in self.graph.items():
ws[n] = wsdef
outSum[n] = sum((e[2] for e in out), 0.0)
# this line for build stable iteration
sorted_keys = sorted(self.graph.keys())
for x in xrange(10): # 10 iters
for n in sorted_keys:
s = 0
for e in self.graph[n]:
s += e[2] / outSum[e[1]] * ws[e[1]]
ws[n] = (1 - self.d) + self.d * s
(min_rank, max_rank) = (sys.float_info[0], sys.float_info[3])
for w in itervalues(ws):
if w < min_rank:
min_rank = w
elif w > max_rank:
max_rank = w
for n, w in ws.items():
# to unify the weights, don't *100.
ws[n] = (w - min_rank / 10.0) / (max_rank - min_rank / 10.0)
return ws
示例7: test_indexer_records_import_of_variable
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import float_info [as 別名]
def test_indexer_records_import_of_variable(self):
client = self.indexSourceCode(
'from sys import float_info\n'
)
self.assertTrue('USAGE: virtual_file -> sys at [1:6|1:8]' in client.references)
self.assertTrue('IMPORT: virtual_file -> sys.float_info at [1:17|1:26]' in client.references)
示例8: test_indexer_records_import_of_aliased_variable
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import float_info [as 別名]
def test_indexer_records_import_of_aliased_variable(self):
client = self.indexSourceCode(
'from sys import float_info as FI\n'
)
self.assertTrue('USAGE: virtual_file -> sys at [1:6|1:8]' in client.references)
self.assertTrue('IMPORT: virtual_file -> sys.float_info at [1:17|1:26]' in client.references)
self.assertTrue('IMPORT: virtual_file -> sys.float_info at [1:31|1:32]' in client.references)
示例9: test_indexer_records_import_of_multiple_aliased_variables_with_single_import_statement
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import float_info [as 別名]
def test_indexer_records_import_of_multiple_aliased_variables_with_single_import_statement(self):
client = self.indexSourceCode(
'from sys import float_info as FI, api_version as AI\n'
)
self.assertTrue('USAGE: virtual_file -> sys at [1:6|1:8]' in client.references)
self.assertTrue('IMPORT: virtual_file -> sys.float_info at [1:17|1:26]' in client.references)
self.assertTrue('IMPORT: virtual_file -> sys.float_info at [1:31|1:32]' in client.references)
self.assertTrue('IMPORT: virtual_file -> sys.api_version at [1:35|1:45]' in client.references)
self.assertTrue('IMPORT: virtual_file -> sys.api_version at [1:50|1:51]' in client.references)
示例10: gaussPDF
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import float_info [as 別名]
def gaussPDF(Data, Mu, Sigma):
realmin = sys.float_info[3]
nbVar, nbData = np.shape(Data)
Data = np.transpose(Data) - np.tile(np.transpose(Mu), (nbData, 1))
prob = np.sum(np.dot(Data, np.linalg.inv(Sigma))*Data, 1)
prob = np.exp(-0.5*prob)/np.sqrt((np.power((2*math.pi), nbVar))*np.absolute(np.linalg.det(Sigma))+realmin)
return prob
示例11: test_attributes
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import float_info [as 別名]
def test_attributes(self):
self.assertIsInstance(sys.api_version, int)
self.assertIsInstance(sys.argv, list)
self.assertIn(sys.byteorder, ("little", "big"))
self.assertIsInstance(sys.builtin_module_names, tuple)
self.assertIsInstance(sys.copyright, basestring)
self.assertIsInstance(sys.exec_prefix, basestring)
self.assertIsInstance(sys.executable, basestring)
self.assertEqual(len(sys.float_info), 11)
self.assertEqual(sys.float_info.radix, 2)
self.assertEqual(len(sys.long_info), 2)
if sys.platform != 'cli':
self.assertTrue(sys.long_info.bits_per_digit % 5 == 0)
else:
self.assertTrue(sys.long_info.bits_per_digit % 8 == 0)
self.assertTrue(sys.long_info.sizeof_digit >= 1)
self.assertEqual(type(sys.long_info.bits_per_digit), int)
self.assertEqual(type(sys.long_info.sizeof_digit), int)
self.assertIsInstance(sys.hexversion, int)
self.assertIsInstance(sys.maxint, int)
if test.test_support.have_unicode:
self.assertIsInstance(sys.maxunicode, int)
self.assertIsInstance(sys.platform, basestring)
self.assertIsInstance(sys.prefix, basestring)
self.assertIsInstance(sys.version, basestring)
vi = sys.version_info
self.assertIsInstance(vi[:], tuple)
self.assertEqual(len(vi), 5)
self.assertIsInstance(vi[0], int)
self.assertIsInstance(vi[1], int)
self.assertIsInstance(vi[2], int)
self.assertIn(vi[3], ("alpha", "beta", "candidate", "final"))
self.assertIsInstance(vi[4], int)
self.assertIsInstance(vi.major, int)
self.assertIsInstance(vi.minor, int)
self.assertIsInstance(vi.micro, int)
self.assertIn(vi.releaselevel, ("alpha", "beta", "candidate", "final"))
self.assertIsInstance(vi.serial, int)
self.assertEqual(vi[0], vi.major)
self.assertEqual(vi[1], vi.minor)
self.assertEqual(vi[2], vi.micro)
self.assertEqual(vi[3], vi.releaselevel)
self.assertEqual(vi[4], vi.serial)
self.assertTrue(vi > (1,0,0))
self.assertIsInstance(sys.float_repr_style, str)
self.assertIn(sys.float_repr_style, ('short', 'legacy'))
示例12: test_attributes
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import float_info [as 別名]
def test_attributes(self):
self.assertIsInstance(sys.api_version, int)
self.assertIsInstance(sys.argv, list)
self.assertIn(sys.byteorder, ("little", "big"))
self.assertIsInstance(sys.builtin_module_names, tuple)
self.assertIsInstance(sys.copyright, basestring)
self.assertIsInstance(sys.exec_prefix, basestring)
self.assertIsInstance(sys.executable, basestring)
self.assertEqual(len(sys.float_info), 11)
self.assertEqual(sys.float_info.radix, 2)
self.assertEqual(len(sys.long_info), 2)
self.assertTrue(sys.long_info.bits_per_digit % 5 == 0)
self.assertTrue(sys.long_info.sizeof_digit >= 1)
self.assertEqual(type(sys.long_info.bits_per_digit), int)
self.assertEqual(type(sys.long_info.sizeof_digit), int)
self.assertIsInstance(sys.hexversion, int)
self.assertIsInstance(sys.maxint, int)
if test.test_support.have_unicode:
self.assertIsInstance(sys.maxunicode, int)
self.assertIsInstance(sys.platform, basestring)
self.assertIsInstance(sys.prefix, basestring)
self.assertIsInstance(sys.version, basestring)
vi = sys.version_info
self.assertIsInstance(vi[:], tuple)
self.assertEqual(len(vi), 5)
self.assertIsInstance(vi[0], int)
self.assertIsInstance(vi[1], int)
self.assertIsInstance(vi[2], int)
self.assertIn(vi[3], ("alpha", "beta", "candidate", "final"))
self.assertIsInstance(vi[4], int)
self.assertIsInstance(vi.major, int)
self.assertIsInstance(vi.minor, int)
self.assertIsInstance(vi.micro, int)
self.assertIn(vi.releaselevel, ("alpha", "beta", "candidate", "final"))
self.assertIsInstance(vi.serial, int)
self.assertEqual(vi[0], vi.major)
self.assertEqual(vi[1], vi.minor)
self.assertEqual(vi[2], vi.micro)
self.assertEqual(vi[3], vi.releaselevel)
self.assertEqual(vi[4], vi.serial)
self.assertTrue(vi > (1,0,0))
self.assertIsInstance(sys.float_repr_style, str)
self.assertIn(sys.float_repr_style, ('short', 'legacy'))
示例13: EM
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import float_info [as 別名]
def EM(Data, Priors0, Mu0, Sigma0):
realmax = sys.float_info[0]
realmin = sys.float_info[3]
loglik_threshold = 1e-10
nbVar, nbData = np.shape(Data)
nbStates = np.size(Priors0)
loglik_old = -realmax
nbStep = 0
Mu = Mu0
Sigma = Sigma0
Priors = Priors0
Pix = np.ndarray(shape = (nbStates, nbData))
Pxi = np.ndarray(shape = (nbData, nbStates))
while 1:
for i in range (0,nbStates):
Pxi[:,i] = gaussPDF(Data,Mu[:,i],Sigma[:,:,i])
Pix_tmp = np.multiply(np.tile(Priors, (nbData, 1)),Pxi)
Pix = np.divide(Pix_tmp,np.tile(np.reshape(np.sum(Pix_tmp,1), (nbData, 1)), (1, nbStates)))
E = np.sum(Pix, 0)
Priors = np.reshape(Priors, (nbStates))
for i in range (0,nbStates):
Priors[i] = E[i]/nbData
Mu[:,i] = np.dot(Data,Pix[:,i])/E[i]
Data_tmp1 = Data - np.tile(np.reshape(Mu[:,i], (nbVar, 1)), (1,nbData))
a = np.transpose(Pix[:, i])
b = np.reshape(a, (1, nbData))
c = np.tile(b, (nbVar, 1))
d = c*Data_tmp1
e = np.transpose(Data_tmp1)
f = np.dot(d,e)
Sigma[:,:,i] = f/E[i]
Sigma[:,:,i] = Sigma[:,:,i] + 0.00001 * np.diag(np.diag(np.ones((nbVar,nbVar))))
for i in range (0,nbStates):
Pxi[:,i] = gaussPDF(Data,Mu[:,i],Sigma[:,:,i])
F = np.dot(Pxi,np.transpose(Priors))
indexes = np.nonzero(F<realmin)
indexes = list(indexes)
indexes = np.reshape(indexes,np.size(indexes))
F[indexes] = realmin
F = np.reshape(F, (nbData, 1))
loglik = np.mean(np.log10(F), 0)
if np.absolute((loglik/loglik_old)-1)<loglik_threshold:
break
loglik_old = loglik
nbStep = nbStep+1
return(Priors,Mu,Sigma, Pix)