本文整理汇总了Python中numpy.float128方法的典型用法代码示例。如果您正苦于以下问题:Python numpy.float128方法的具体用法?Python numpy.float128怎么用?Python numpy.float128使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类numpy
的用法示例。
在下文中一共展示了numpy.float128方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_returned_dtype
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import float128 [as 别名]
def test_returned_dtype(self):
dtypes = [np.int16, np.int32, np.int64, np.float32, np.float64]
if hasattr(np, 'float128'):
dtypes.append(np.float128)
for dtype in dtypes:
s = Series(range(10), dtype=dtype)
group_a = ['mean', 'std', 'var', 'skew', 'kurt']
group_b = ['min', 'max']
for method in group_a + group_b:
result = getattr(s, method)()
if is_integer_dtype(dtype) and method in group_a:
assert result.dtype == np.float64
else:
assert result.dtype == dtype
示例2: svm_topk_smooth_py_1
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import float128 [as 别名]
def svm_topk_smooth_py_1(x, y, tau, k):
x, y = to_numpy(x), to_numpy(y)
x = x.astype(np.float128)
tau = float(tau)
n_samples, n_classes = x.shape
exp = np.exp(x * 1. / (k * tau))
term_1 = np.zeros(n_samples)
for indices in itertools.combinations(range(n_classes), k):
delta = 1. - np.sum(indices == y[:, None], axis=1)
term_1 += np.product(exp[:, indices], axis=1) * np.exp(delta / tau)
term_2 = np.zeros(n_samples)
for i in range(n_samples):
all_but_y = [j for j in range(n_classes) if j != y[i]]
for indices in itertools.combinations(all_but_y, k - 1):
term_2[i] += np.product(exp[i, indices]) * exp[i, y[i]]
loss = tau * (np.log(term_1) - np.log(term_2))
return loss
示例3: test_diric
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import float128 [as 别名]
def test_diric(self):
# Test behavior near multiples of 2pi. Regression test for issue
# described in gh-4001.
n_odd = [1, 5, 25]
x = np.array(2*np.pi + 5e-5).astype(np.float32)
assert_almost_equal(special.diric(x, n_odd), 1.0, decimal=7)
x = np.array(2*np.pi + 1e-9).astype(np.float64)
assert_almost_equal(special.diric(x, n_odd), 1.0, decimal=15)
x = np.array(2*np.pi + 1e-15).astype(np.float64)
assert_almost_equal(special.diric(x, n_odd), 1.0, decimal=15)
if hasattr(np, 'float128'):
# No float128 available in 32-bit numpy
x = np.array(2*np.pi + 1e-12).astype(np.float128)
assert_almost_equal(special.diric(x, n_odd), 1.0, decimal=19)
n_even = [2, 4, 24]
x = np.array(2*np.pi + 1e-9).astype(np.float64)
assert_almost_equal(special.diric(x, n_even), -1.0, decimal=15)
# Test at some values not near a multiple of pi
x = np.arange(0.2*np.pi, 1.0*np.pi, 0.2*np.pi)
octave_result = [0.872677996249965, 0.539344662916632,
0.127322003750035, -0.206011329583298]
assert_almost_equal(special.diric(x, 3), octave_result, decimal=15)
示例4: _joint_mi
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import float128 [as 别名]
def _joint_mi(s1, s2, t, alph_s1, alph_s2, alph_t):
"""
Joint MI estimator in the samples domain
"""
[s12, alph_s12] = _join_variables(s1, s2, alph_s1, alph_s2)
t_count = np.zeros(alph_t, dtype=np.int)
s12_count = np.zeros(alph_s12, dtype=np.int)
joint_t_s12_count = np.zeros((alph_t, alph_s12), dtype=np.int)
num_samples = len(t)
for obs in range(0, num_samples):
t_count[t[obs]] += 1
s12_count[s12[obs]] += 1
joint_t_s12_count[t[obs], s12[obs]] += 1
t_prob = np.divide(t_count, num_samples).astype('float128')
s12_prob = np.divide(s12_count, num_samples).astype('float128')
joint_t_s12_prob = np.divide(joint_t_s12_count, num_samples).astype('float128')
jmi = _mi_prob(t_prob, s12_prob, joint_t_s12_prob)
return jmi
示例5: _mi_prob
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import float128 [as 别名]
def _mi_prob(s1_prob, s2_prob, joint_s1_s2_prob):
""" MI estimator in the prob domain."""
total = np.zeros(1).astype('float128')
[alph_s1, alph_s2] = np.shape(joint_s1_s2_prob)
for sym_s1 in range(0, alph_s1):
for sym_s2 in range(0, alph_s2):
if (s1_prob[sym_s1] * s2_prob[sym_s2] *
joint_s1_s2_prob[sym_s1, sym_s2] > 0):
local_contrib = (
np.log(joint_s1_s2_prob[sym_s1, sym_s2]) -
np.log(s1_prob[sym_s1]) -
np.log(s2_prob[sym_s2])) / np.log(2)
weighted_contrib = (
joint_s1_s2_prob[sym_s1, sym_s2] *
local_contrib)
else:
weighted_contrib = 0
total += weighted_contrib
return total
示例6: _mi_prob
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import float128 [as 别名]
def _mi_prob(self, s1_prob, s2_prob, joint_s1_s2_prob):
"""MI estimator in the prob domain."""
total = np.zeros(1).astype('float128')
[alph_s1, alph_s2] = np.shape(joint_s1_s2_prob)
for sym_s1 in range(0, alph_s1):
for sym_s2 in range(0, alph_s2):
if (s1_prob[sym_s1] * s2_prob[sym_s2] *
joint_s1_s2_prob[sym_s1, sym_s2] > 0):
local_contrib = (
np.log(joint_s1_s2_prob[sym_s1, sym_s2]) -
np.log(s1_prob[sym_s1]) -
np.log(s2_prob[sym_s2])
) / np.log(2)
weighted_contrib = (joint_s1_s2_prob[sym_s1, sym_s2] *
local_contrib)
else:
weighted_contrib = 0
total += weighted_contrib
return total
示例7: _joint_mi
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import float128 [as 别名]
def _joint_mi(self, s1, s2, t, alph_s1, alph_s2, alph_t):
"""Joint MI estimator in the samples domain."""
[s12, alph_s12] = _join_variables(s1, s2, alph_s1, alph_s2)
t_count = np.zeros(alph_t, dtype=np.int)
s12_count = np.zeros(alph_s12, dtype=np.int)
joint_t_s12_count = np.zeros((alph_t, alph_s12), dtype=np.int)
num_samples = len(t)
for obs in range(0, num_samples):
t_count[t[obs]] += 1
s12_count[s12[obs]] += 1
joint_t_s12_count[t[obs], s12[obs]] += 1
t_prob = np.divide(t_count, num_samples).astype('float128')
s12_prob = np.divide(s12_count, num_samples).astype('float128')
joint_t_s12_prob = np.divide(joint_t_s12_count,
num_samples).astype('float128')
return self._mi_prob(t_prob, s12_prob, joint_t_s12_prob)
示例8: exp_stats
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import float128 [as 别名]
def exp_stats(e,e_post,a):
if a < np.float128(1.0):
H,H_post = exp_hist(e),exp_hist(e_post)
upper,lower,value = 0,0,np.float128(1.0)
for row in H:
if row[0] >= a: upper += int(row[1])
for row in H_post:
lower += int(row[1])
if lower >= upper:
value = row[0]
break
h = np.array([e[g] for g in e])
x = [a,value,len(e)-upper,upper,np.median(h),np.mean(h),np.std(h)]
else:
x = [a,a,len(e),0,np.float128(0.0),np.float128(0.0),np.float128(0.0)]
return x
#given the old group expectation E and cutoff t,b value alpha
#estimates a alpha_post value that uses the histogram of the
#posterior estimate E_post to adjust the alpha value
示例9: select_groups
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import float128 [as 别名]
def select_groups(W,gamma=0.0):
G = {}
for t in W:
G[t] = {}
for b in W[t]:
C,G[t][b] = [],{}
for g in W[t][b]:
if len(g)<=1 and W[t][b][g]>=gamma: C += [g[0]]
if len(C)<=0:
G[t][b] = {(None,):np.float128(0.0)}
else:
C = sorted(C)
for i in range(1,len(C)+1):
for j in it.combinations(C,i):
G[t][b][j] = W[t][b][j]
return G
#pppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp
#given a svul, join idxs from list j
################################################################################
#given a svul, join idxs from list j
示例10: test_np_builtin
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import float128 [as 别名]
def test_np_builtin(self):
self.pod_util(np.int64(42))
self.pod_util(np.int32(42))
self.pod_util(np.int16(42))
self.pod_util(np.int8(42))
self.pod_util(np.uint64(42))
self.pod_util(np.uint32(42))
self.pod_util(np.uint16(42))
self.pod_util(np.uint8(42))
self.pod_util(np.float16(42))
self.pod_util(np.float32(42))
self.pod_util(np.float64(42))
# self.pod_util(np.float128(42))
self.pod_util(np.complex64(42))
self.pod_util(np.complex128(42))
# self.pod_util(np.complex256(42))
示例11: numpy2bifrost
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import float128 [as 别名]
def numpy2bifrost(dtype):
if dtype == np.int8: return _bf.BF_DTYPE_I8
elif dtype == np.int16: return _bf.BF_DTYPE_I16
elif dtype == np.int32: return _bf.BF_DTYPE_I32
elif dtype == np.uint8: return _bf.BF_DTYPE_U8
elif dtype == np.uint16: return _bf.BF_DTYPE_U16
elif dtype == np.uint32: return _bf.BF_DTYPE_U32
elif dtype == np.float16: return _bf.BF_DTYPE_F16
elif dtype == np.float32: return _bf.BF_DTYPE_F32
elif dtype == np.float64: return _bf.BF_DTYPE_F64
elif dtype == np.float128: return _bf.BF_DTYPE_F128
elif dtype == ci8: return _bf.BF_DTYPE_CI8
elif dtype == ci16: return _bf.BF_DTYPE_CI16
elif dtype == ci32: return _bf.BF_DTYPE_CI32
elif dtype == cf16: return _bf.BF_DTYPE_CF16
elif dtype == np.complex64: return _bf.BF_DTYPE_CF32
elif dtype == np.complex128: return _bf.BF_DTYPE_CF64
elif dtype == np.complex256: return _bf.BF_DTYPE_CF128
else: raise ValueError("Unsupported dtype: " + str(dtype))
示例12: numpy2string
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import float128 [as 别名]
def numpy2string(dtype):
if dtype == np.int8: return 'i8'
elif dtype == np.int16: return 'i16'
elif dtype == np.int32: return 'i32'
elif dtype == np.int64: return 'i64'
elif dtype == np.uint8: return 'u8'
elif dtype == np.uint16: return 'u16'
elif dtype == np.uint32: return 'u32'
elif dtype == np.uint64: return 'u64'
elif dtype == np.float16: return 'f16'
elif dtype == np.float32: return 'f32'
elif dtype == np.float64: return 'f64'
elif dtype == np.float128: return 'f128'
elif dtype == np.complex64: return 'cf32'
elif dtype == np.complex128: return 'cf64'
elif dtype == np.complex256: return 'cf128'
else: raise TypeError("Unsupported dtype: " + str(dtype))
示例13: process_csv
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import float128 [as 别名]
def process_csv(filename, val=0):
sum_f = np.float128([0.0] * OUTPUT_DIM)
sum_sq_f = np.float128([0.0] * OUTPUT_DIM)
print ("output_dim: %d" % OUTPUT_DIM)
lines = read_csv(filename)
# leave val% for validation
train_seq = []
valid_seq = []
num = 0
for ln in lines:
train_seq.append(ln)
num += 1
print ("training seq:%d" % num)
for cnt in range(len(train_seq)):
sum_f += train_seq[cnt][1][:]
sum_sq_f += train_seq[cnt][1][:] * train_seq[cnt][1][:]
mean = sum_f / len(train_seq)
var = sum_sq_f / len(train_seq) - mean * mean
std = np.sqrt(var)
print (len(train_seq), len(valid_seq))
print ("current mean, std")
print (mean, std)
return (train_seq, valid_seq), (mean, std)
示例14: getCsvData
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import float128 [as 别名]
def getCsvData():
dtypes = {
"int8_value": numpy.int8,
"int16_value": numpy.int16,
"int32_value": numpy.int32,
#"int64_value": numpy.int64, # OverFlowError
"uint8_value": numpy.uint8,
"uint16_value": numpy.uint16,
"uint32_value": numpy.uint32,
#"uint64_value": numpy.uint64, # OverFlowError
"float16_value": numpy.float16,
"float32_value": numpy.float32,
"float64_value": numpy.float64,
# "float128_value": numpy.float128,
"bool_value": numpy.bool_
}
delimiter = ","
encoding = "utf-8"
parse_dates = ["timestamp_value"]
path = os.path.join(os.getcwd(), "examples/testData/test1.csv")
if not os.path.exists(path):
path = os.path.join(os.getcwd(), "testData/test1.csv")
df = pandas.read_csv(
path,
dtype=dtypes,
delimiter=delimiter,
encoding=encoding,
parse_dates=parse_dates
)
try:
df["int64_value"] = df["int64_value"].astype(numpy.int64)
df["uint64_value"] = df["uint64_value"].astype(numpy.uint64)
except:
raise
return df
示例15: _rews_validation
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import float128 [as 别名]
def _rews_validation(rews: np.ndarray, acts: np.ndarray):
if rews.shape != (len(acts),):
raise ValueError(
"rewards must be 1D array, one entry for each action: "
f"{rews.shape} != ({len(acts)},)"
)
if rews.dtype not in [np.float32, np.float64, np.float128]:
raise ValueError("rewards dtype {self.rews.dtype} not a float")