本文整理汇总了Python中numpy.float64函数的典型用法代码示例。如果您正苦于以下问题:Python float64函数的具体用法?Python float64怎么用?Python float64使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了float64函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_init
def test_init(self):
import numpy as np
import math
import sys
assert np.intp() == np.intp(0)
assert np.intp("123") == np.intp(123)
raises(TypeError, np.intp, None)
assert np.float64() == np.float64(0)
assert math.isnan(np.float64(None))
assert np.bool_() == np.bool_(False)
assert np.bool_("abc") == np.bool_(True)
assert np.bool_(None) == np.bool_(False)
assert np.complex_() == np.complex_(0)
# raises(TypeError, np.complex_, '1+2j')
assert math.isnan(np.complex_(None))
for c in ["i", "I", "l", "L", "q", "Q"]:
assert np.dtype(c).type().dtype.char == c
for c in ["l", "q"]:
assert np.dtype(c).type(sys.maxint) == sys.maxint
for c in ["L", "Q"]:
assert np.dtype(c).type(sys.maxint + 42) == sys.maxint + 42
assert np.float32(np.array([True, False])).dtype == np.float32
assert type(np.float32(np.array([True]))) is np.ndarray
assert type(np.float32(1.0)) is np.float32
a = np.array([True, False])
assert np.bool_(a) is a
示例2: do_rangecheck
def do_rangecheck(cf,ds,section='',series='',code=2):
'''Applies a range check to data series listed in the control file. Data values that
are less than the lower limit or greater than the upper limit are replaced with
c.missing_value and the corresponding QC flag element is set to 2.'''
if 'RangeCheck' not in cf[section][series].keys(): return
if 'Lower' in cf[section][series]['RangeCheck'].keys():
lwr = numpy.array(eval(cf[section][series]['RangeCheck']['Lower']))
valid_lower = numpy.min(lwr)
lwr = lwr[ds.series['Month']['Data']-1]
index = numpy.where((abs(ds.series[series]['Data']-numpy.float64(c.missing_value))>c.eps)&
(ds.series[series]['Data']<lwr))
ds.series[series]['Data'][index] = numpy.float64(c.missing_value)
ds.series[series]['Flag'][index] = numpy.int32(code)
ds.series[series]['Attr']['rangecheck_lower'] = cf[section][series]['RangeCheck']['Lower']
if 'Upper' in cf[section][series]['RangeCheck'].keys():
upr = numpy.array(eval(cf[section][series]['RangeCheck']['Upper']))
valid_upper = numpy.min(upr)
upr = upr[ds.series['Month']['Data']-1]
index = numpy.where((abs(ds.series[series]['Data']-numpy.float64(c.missing_value))>c.eps)&
(ds.series[series]['Data']>upr))
ds.series[series]['Data'][index] = numpy.float64(c.missing_value)
ds.series[series]['Flag'][index] = numpy.int32(code)
ds.series[series]['Attr']['rangecheck_upper'] = cf[section][series]['RangeCheck']['Upper']
ds.series[series]['Attr']['valid_range'] = str(valid_lower)+','+str(valid_upper)
if 'RangeCheck' not in ds.globalattributes['Functions']:
ds.globalattributes['Functions'] = ds.globalattributes['Functions']+',RangeCheck'
示例3: calc_pca
def calc_pca(feature):
# Filter out super high numbers due to some instability in the network
feature[feature>5] = 5
feature[feature<-5] = -5
#### Missing an image guided filter with the image as input
##
##########
# change to double precision
feature = np.float64(feature)
# retrieve size of feature array
shape = feature.shape
[h, w, d] = feature.shape
# resize to a two-dimensional array
feature = np.reshape(feature, (h*w,d))
# calculate average of each column
featmean = np.average(feature,0)
onearray = np.ones((h*w,1))
featmeanarray = np.multiply(np.ones((h*w,1)),featmean)
feature = np.subtract(feature,featmeanarray)
feature_transpose = np.transpose(feature)
cover = np.dot(feature_transpose, feature)
# get largest eigenvectors of the array
val,vecs = eigs(cover, k=3, which='LI')
pcafeature = np.dot(feature, vecs)
pcafeature = np.reshape(pcafeature,(h,w,3))
pcafeature = np.float64(pcafeature)
return pcafeature
示例4: eaxis
def eaxis(y, uid, camname, hdf5_data, E0=20.35, etay=0, etapy=0):
logger.log(level=loggerlevel, msg='Getting energy axis...')
# eaxis = E200.eaxis(camname=camname, y=y, res=res, E0=20.35, etay=0, etapy=0, ymotor=ymotor)
imgstr = hdf5_data['raw']['images'][str(camname)]
res = np.float64(imgstr['RESOLUTION'][0, 0])
res = res*np.float64(1.0e-6)
logger.log(level=loggerlevel, msg='Camera detected: {}'.format(camname))
if camname == 'ELANEX':
ymotor = hdf5_data['raw']['scalars']['XPS_LI20_DWFA_M5']['dat']
ymotor = mt.derefdataset(ymotor, hdf5_data.file)
ymotor = ymotor[0]*1e-3
logger.log(level=loggerlevel, msg='Original ymotor is: {}'.format(ymotor))
raw_rf = hdf5_data['raw']
scalars_rf = raw_rf['scalars']
setQS_str = scalars_rf['step_value']
setQS_dat = E200.E200_api_getdat(setQS_str, uid).dat[0]
setQS = mt.hardcode.setQS(setQS_dat)
logger.log(level=loggerlevel, msg='Eaxis''s setQS is: {}'.format(setQS_dat))
ymotor = setQS.elanex_y_motor()*1e-3
logger.log(level=loggerlevel, msg='Reconstructed ymotor is: {ymotor}'.format(ymotor=ymotor))
return eaxis_ELANEX(y=y, res=res, etay=etay, etapy=etapy, ymotor=ymotor)
elif camname == 'CMOS_FAR':
return eaxis_CMOS_far(y=y, res=res, E0=E0, etay=etay, etapy=etapy)
else:
msg = 'No energy axis available for camera: {}'.format(camname)
logger.log(level=loggerlevel, msg=msg)
raise NotImplementedError(msg)
示例5: _combine_match_index
def _combine_match_index(self, other, func, level=None, fill_value=None):
new_data = {}
if fill_value is not None:
raise NotImplementedError
if level is not None:
raise NotImplementedError
new_index = self.index.union(other.index)
this = self
if self.index is not new_index:
this = self.reindex(new_index)
if other.index is not new_index:
other = other.reindex(new_index)
for col, series in compat.iteritems(this):
new_data[col] = func(series.values, other.values)
# fill_value is a function of our operator
if isnull(other.fill_value) or isnull(self.default_fill_value):
fill_value = np.nan
else:
fill_value = func(np.float64(self.default_fill_value),
np.float64(other.fill_value))
return self._constructor(new_data,
index=new_index,
columns=self.columns,
default_fill_value=fill_value,
fill_value=self.default_fill_value).__finalize__(self)
示例6: testMulArray
def testMulArray(self):
from numpy import arange, round
a = arange(0, 60, dtype = 'd').reshape(3,4,5) + .3
r1 = self.rxns['NTRplOH']
r2 = r1 * a
for spcn in "NTR OH".split():
spc = self.spcs[spcn]
self.assertTrue((r2[spc] == -a).all())
for spcn in "HNO3 HO2".split():
spc = self.spcs[spcn]
self.assertTrue((r2[spc] == a).all())
for spcn in "FORM ALD2 ALDX".split():
spc = self.spcs[spcn]
self.assertTrue((r2[spc] == (a * float64(.33))).all())
for spcn in ["ALD"]:
spc = self.spcs[spcn]
# Value is not exact because of addition
self.assertTrue((round(r2[spc], decimals = 8) == round(a * float64(.99), decimals = 8)).all())
for spcn in ["PAR"]:
spc = self.spcs[spcn]
self.assertTrue((r2[spc] == (-a * .66)).all())
示例7: loadModel
def loadModel(self):
f = open(self.modelPath)
list = f.readlines()
self.vocabSize = int(list[0].strip())
self.topicK = int(list[1].strip())
# self.alpha = np.asarray( [float(list[2].strip())] * self.topicK )
# self.eta = float(list[3].strip())
self.topicMatrix = np.zeros((self.topicK, self.vocabSize))
self.wordMatrix = np.zeros((self.vocabSize, self.topicK))
j = -1
location = 0
for i in range(len(list)):
if i < 2:
continue
if "#TOPIC#" in list[i]:
j = j + 1
continue
l = list[i].split("\t")
if self.index.has_key(l[0].strip()):
self.topicMatrix[j][self.index[l[0].strip()]] = np.float64(l[1].strip())
else:
self.index[l[0].strip()] = location
location = location + 1
self.topicMatrix[j][self.index[l[0].strip()]] = np.float64(l[1].strip())
self.wordMatrix = np.transpose(self.topicMatrix)
self.indexList = sorted(self.index.iteritems(), key=lambda d: d[1])
self.eta = 1.0 / 200
self.alpha = np.asarray([1.0 / self.topicK for i in xrange(self.topicK)])
self.minimum_probability = 2.0 / self.topicK
self.stats = self.topicMatrix
self.expElogbeta = np.exp(dirichlet_expectation(self.eta + self.stats))
示例8: test_maybe_convert_scalar
def test_maybe_convert_scalar(self):
# pass thru
result = maybe_convert_scalar('x')
assert result == 'x'
result = maybe_convert_scalar(np.array([1]))
assert result == np.array([1])
# leave scalar dtype
result = maybe_convert_scalar(np.int64(1))
assert result == np.int64(1)
result = maybe_convert_scalar(np.int32(1))
assert result == np.int32(1)
result = maybe_convert_scalar(np.float32(1))
assert result == np.float32(1)
result = maybe_convert_scalar(np.int64(1))
assert result == np.float64(1)
# coerce
result = maybe_convert_scalar(1)
assert result == np.int64(1)
result = maybe_convert_scalar(1.0)
assert result == np.float64(1)
result = maybe_convert_scalar(Timestamp('20130101'))
assert result == Timestamp('20130101').value
result = maybe_convert_scalar(datetime(2013, 1, 1))
assert result == Timestamp('20130101').value
result = maybe_convert_scalar(Timedelta('1 day 1 min'))
assert result == Timedelta('1 day 1 min').value
示例9: imageGradientY
def imageGradientY(image):
""" This function differentiates an image in the Y direction.
Note: See lectures 02-06 (Differentiating an image in X and Y) for a good
explanation of how to perform this operation.
The Y direction means that you are subtracting rows:
der. F(x, y) = F(x, y+1) - F(x, y)
This corresponds to image[r,c] = image[r+1,c] - image[r,c]
You should compute the absolute value of the differences in order to avoid
setting a pixel to a negative value which would not make sense.
We want you to iterate the image to complete this function. You may NOT use
any functions that automatically do this for you.
Args:
image (numpy.ndarray): A grayscale image represented in a numpy array.
Returns:
output (numpy.ndarray): The image gradient in the Y direction. The shape
of the output array should have a height that is
one less than the original since no calculation
can be done once the last row is reached.
"""
# WRITE YOUR CODE HERE.
shift1 = np.float64(np.roll(image,-1,axis=0))
diff = np.uint8(np.absolute(np.float64(image) - shift1))[0:-1,:]
return diff
示例10: get_field_rotation_BB_integral
def get_field_rotation_BB_integral(lsamp, clcurl, cl_E_unlensed_sp, lmax=None, lsamp_out=None, acc=1, raw_cl=False):
CurlSp = InterpolatedUnivariateSpline(lsamp, clcurl)
lmax = lmax or lsamp[-1]
if lsamp_out is None: lsamp_out = np.array([L for L in lsamp if L <= lmax // 2])
Bcurl = np.zeros(lsamp_out.shape)
for i, ll in enumerate(lsamp_out):
l = np.float64(ll)
for llp in range(10, lmax):
lp = np.float64(llp)
if abs(ll - llp) > 200 and lp > 200:
nphi = 2 * int(min(lp / 10 * acc, 200)) + 1
elif ll > 2000:
nphi = 2 * int(lp / 10 * acc) + 1
else:
nphi = 2 * int(lp) + 1
dphi = 2 * np.pi / nphi
phi = np.linspace(dphi, (nphi - 1) / 2 * dphi, (nphi - 1) // 2)
w = 2 * np.ones(phi.size)
cosphi = np.cos(phi)
sinphi = np.sin(phi)
sin2phi = np.sin(2 * phi)
lpp = np.sqrt(lp ** 2 + l ** 2 - 2 * cosphi * l * lp)
w[lpp < 2] = 0
w[lpp > lmax] = 0
curls = CurlSp(lpp)
dCEs = cl_E_unlensed_sp(lp) * lp * dphi
crossterm = sinphi * l * lp / lpp ** 2
Bcurl[i] += np.dot(w, curls * (crossterm * sin2phi) ** 2) * dCEs
Bcurl *= 4 / (2 * np.pi) ** 2
if not raw_cl: Bcurl *= lsamp_out * (lsamp_out + 1) / (2 * np.pi)
return lsamp_out, Bcurl
示例11: test_maybe_convert_scalar
def test_maybe_convert_scalar(self):
# pass thru
result = com._maybe_convert_scalar('x')
self.assertEqual(result, 'x')
result = com._maybe_convert_scalar(np.array([1]))
self.assertEqual(result, np.array([1]))
# leave scalar dtype
result = com._maybe_convert_scalar(np.int64(1))
self.assertEqual(result, np.int64(1))
result = com._maybe_convert_scalar(np.int32(1))
self.assertEqual(result, np.int32(1))
result = com._maybe_convert_scalar(np.float32(1))
self.assertEqual(result, np.float32(1))
result = com._maybe_convert_scalar(np.int64(1))
self.assertEqual(result, np.float64(1))
# coerce
result = com._maybe_convert_scalar(1)
self.assertEqual(result, np.int64(1))
result = com._maybe_convert_scalar(1.0)
self.assertEqual(result, np.float64(1))
result = com._maybe_convert_scalar(pd.Timestamp('20130101'))
self.assertEqual(result, pd.Timestamp('20130101').value)
result = com._maybe_convert_scalar(datetime(2013, 1, 1))
self.assertEqual(result, pd.Timestamp('20130101').value)
result = com._maybe_convert_scalar(pd.Timedelta('1 day 1 min'))
self.assertEqual(result, pd.Timedelta('1 day 1 min').value)
示例12: test_get_dimensions
def test_get_dimensions():
'''
Test various ways of getting/comparing the dimensions of a quantity.
'''
q = 500 * ms
assert get_dimensions(q) is get_or_create_dimension(q.dimensions._dims)
assert get_dimensions(q) is q.dimensions
assert q.has_same_dimensions(3 * second)
dims = q.dimensions
assert_equal(dims.get_dimension('time'), 1.)
assert_equal(dims.get_dimension('length'), 0)
assert get_dimensions(5) is DIMENSIONLESS
assert get_dimensions(5.0) is DIMENSIONLESS
assert get_dimensions(np.array(5, dtype=np.int)) is DIMENSIONLESS
assert get_dimensions(np.array(5.0)) is DIMENSIONLESS
assert get_dimensions(np.float32(5.0)) is DIMENSIONLESS
assert get_dimensions(np.float64(5.0)) is DIMENSIONLESS
assert is_scalar_type(5)
assert is_scalar_type(5.0)
assert is_scalar_type(np.array(5, dtype=np.int))
assert is_scalar_type(np.array(5.0))
assert is_scalar_type(np.float32(5.0))
assert is_scalar_type(np.float64(5.0))
assert_raises(TypeError, lambda: get_dimensions('a string'))
# wrong number of indices
assert_raises(TypeError, lambda: get_or_create_dimension([1, 2, 3, 4, 5, 6]))
# not a sequence
assert_raises(TypeError, lambda: get_or_create_dimension(42))
示例13: _get_op_result_fill_value
def _get_op_result_fill_value(self, other, func):
own_default = self.default_fill_value
if isinstance(other, DataFrame):
# i.e. called from _combine_frame
other_default = getattr(other, 'default_fill_value', np.nan)
# if the fill values are the same use them? or use a valid one
if own_default == other_default:
# TOOD: won't this evaluate as False if both are np.nan?
fill_value = own_default
elif np.isnan(own_default) and not np.isnan(other_default):
fill_value = other_default
elif not np.isnan(own_default) and np.isnan(other_default):
fill_value = own_default
else:
fill_value = None
elif isinstance(other, SparseSeries):
# i.e. called from _combine_match_index
# fill_value is a function of our operator
if isna(other.fill_value) or isna(own_default):
fill_value = np.nan
else:
fill_value = func(np.float64(own_default),
np.float64(other.fill_value))
else:
raise NotImplementedError(type(other))
return fill_value
示例14: read_as_sigmas
def read_as_sigmas(options, infiles):
"""Read overdispersion parameters for allele-specific test
(Beta-Binomial). Expect one for each individual."""
if (options.as_disp):
disp_file = open(options.as_disp)
line = disp_file.readline()
as_sigmas = []
while line:
val = np.float64(line.strip())
if val < 0.0 or val > 1.0:
raise ValueError("expected as_sigma values to be "
" in range 0.0-1.0, but got %g" %
val)
as_sigmas.append(np.float64(line.strip()))
line = disp_file.readline()
disp_file.close()
if len(as_sigmas) != len(infiles):
raise ValueError("expected %d values in as_disp file "
"(one for each input file) but got "
"%d" % (len(infiles), len(as_sigmas)))
else:
as_sigmas = [0.001] * len(infiles)
return as_sigmas
示例15: Provisional
def Provisional(self,N,provis,unknowns):
j=0
finalX=Points('New Provisional Points')
orientations={}
for i in unknowns:
name= i[0:-2]
variable = i[-1]
if variable=="o":
orientations[name]= float64(N[j])
j+=1
continue
x=provis[name].x
y=provis[name].y
h=provis[name].h
if not finalX.has_key(name):
finalX[name]= Point(0,0,0,False,name)
if variable=="x":
finalX[name].ChangeVariable(variable,float64(x+N[j]))
j+=1
continue
if variable=="y":
finalX[name].ChangeVariable(variable,float64(y+N[j]))
j+=1
continue
if variable=="h":
finalX[name].ChangeVariable(variable,float64(h+N[j]))
j+=1
continue
return finalX