本文整理汇总了Python中numpy.float32函数的典型用法代码示例。如果您正苦于以下问题:Python float32函数的具体用法?Python float32怎么用?Python float32使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了float32函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
开发者ID:GaussDing,项目名称:pypy,代码行数:27,代码来源:test_scalar.py
示例2: _init_params
def _init_params(self):
# Left weight matrix
self.W_hh = theano.shared(
self.init_fn(self.n_hids, self.n_hids, self.sparsity, self.scale, rng=self.rng), name="W_%s" % self.name
)
self.params = [self.W_hh]
# Right weight matrix
self.U_hh = theano.shared(
self.init_fn(self.n_hids, self.n_hids, self.sparsity, self.scale, rng=self.rng), name="U_%s" % self.name
)
self.params += [self.U_hh]
# Bias
self.b_hh = theano.shared(self.bias_fn(self.n_hids, self.bias_scale, self.rng), name="b_%s" % self.name)
self.params += [self.b_hh]
# gaters
# if self.conv_mode == "conv":
self.GW_hh = theano.shared(numpy.float32(0.01 * self.rng.randn(self.n_hids, 3)), name="GW_%s" % self.name)
self.params += [self.GW_hh]
self.GU_hh = theano.shared(numpy.float32(0.01 * self.rng.randn(self.n_hids, 3)), name="GU_%s" % self.name)
self.params += [self.GU_hh]
self.Gb_hh = theano.shared(self.bias_fn(3, self.bias_scale, self.rng), name="Gb_%s" % self.name)
self.params += [self.Gb_hh]
self.params_grad_scale = [self.grad_scale for x in self.params]
self.restricted_params = [x for x in self.params]
if self.weight_noise:
self.nW_hh = theano.shared(self.W_hh.get_value() * 0, name="noise_" + self.W_hh.name)
self.nU_hh = theano.shared(self.U_hh.get_value() * 0, name="noise_" + self.U_hh.name)
self.nb_hh = theano.shared(self.b_hh.get_value() * 0, name="noise_" + self.b_hh.name)
self.noise_params = [self.nW_hh, self.nU_hh, self.nb_hh]
self.noise_params_shape_fn = [constant_shape(x.get_value().shape) for x in self.noise_params]
开发者ID:ktho22,项目名称:speech_synthesis,代码行数:31,代码来源:rconv_layers.py
示例3: adadelta
def adadelta(lr, tparams, grads, inp, cost):
zipped_grads = [theano.shared(p.get_value() * numpy.float32(0.),
name='%s_grad' % k)
for k, p in tparams.iteritems()]
running_up2 = [theano.shared(p.get_value() * numpy.float32(0.),
name='%s_rup2' % k)
for k, p in tparams.iteritems()]
running_grads2 = [theano.shared(p.get_value() * numpy.float32(0.),
name='%s_rgrad2' % k)
for k, p in tparams.iteritems()]
zgup = [(zg, g) for zg, g in zip(zipped_grads, grads)]
rg2up = [(rg2, 0.95 * rg2 + 0.05 * (g ** 2))
for rg2, g in zip(running_grads2, grads)]
f_grad_shared = theano.function(inp, cost, updates=zgup+rg2up,
profile=profile)
updir = [-tensor.sqrt(ru2 + 1e-6) / tensor.sqrt(rg2 + 1e-6) * zg
for zg, ru2, rg2 in zip(zipped_grads, running_up2,
running_grads2)]
ru2up = [(ru2, 0.95 * ru2 + 0.05 * (ud ** 2))
for ru2, ud in zip(running_up2, updir)]
param_up = [(p, p + ud) for p, ud in zip(itemlist(tparams), updir)]
f_update = theano.function([lr], [], updates=ru2up+param_up,
on_unused_input='ignore', profile=profile)
return f_grad_shared, f_update
开发者ID:G-Wang,项目名称:dl4mt-material,代码行数:29,代码来源:nmt.py
示例4: _testReduceSum
def _testReduceSum(self,
expected_result,
dtype,
test_inputs,
rtol=1e-3,
atol=1e-4):
"""Tests reduce sum on a list of input arrays.
For each array in test_inputs, check that performing reduce sum on the array
produces a value that is close to the expected result.
Args:
expected_result: the expected result.
dtype: the data type of the reduce sum operation.
test_inputs: a list of input arrays for the reduce sum operation.
rtol: the relative error.
atol: the absolute error.
"""
for test_input in test_inputs:
with self.test_session() as sess:
with self.test_scope():
a = array_ops.placeholder(dtype)
index = array_ops.placeholder(dtypes.int32)
out = math_ops.reduce_sum(a, index)
result = sess.run(out, {
a: np.array(test_input, dtype=dtype),
index: [0]
})
# Compare the results using float32 type.
self.assertAllClose(
np.float32(result),
np.float32(expected_result),
rtol=rtol,
atol=atol)
开发者ID:BhaskarNallani,项目名称:tensorflow,代码行数:35,代码来源:reduce_ops_test.py
示例5: coolBlack
def coolBlack():
IMAGE_WEIGHT = 0.5
image = cv2.imread("G:/Filters/wasim.jpg",0)
black = cv2.imread("G:/Filters/black5.jpg",0)
black = cv2.resize(black, image.shape[::-1])
res1 = cv2.addWeighted(image, IMAGE_WEIGHT, black, 1 - IMAGE_WEIGHT, 1)
#NORMALIZE IMAGES
image = np.float32(image)
black = np.float32(black)
image /= 255
black /= 200
res = image*black
cv2.imshow("RES", res)
cv2.waitKey(0)
fname = "G:/Filtes/temp.jpg"
cv2.imwrite(fname, res)
res = cv2.imread(fname, 0)
cv2.imshow("BLACK", res)
cv2.waitKey(0)
开发者ID:wasimblogs,项目名称:PhotoFilter,代码行数:28,代码来源:PhotoFilters.py
示例6: affine_skew
def affine_skew(tilt, phi, img, mask=None):
'''
affine_skew(tilt, phi, img, mask=None) -> skew_img, skew_mask, Ai
Ai - is an affine transform matrix from skew_img to img
'''
h, w = img.shape[:2]
if mask is None:
mask = np.zeros((h, w), np.uint8)
mask[:] = 255
A = np.float32([[1, 0, 0], [0, 1, 0]])
if phi != 0.0:
phi = np.deg2rad(phi)
s, c = np.sin(phi), np.cos(phi)
A = np.float32([[c,-s], [ s, c]])
corners = [[0, 0], [w, 0], [w, h], [0, h]]
tcorners = np.int32( np.dot(corners, A.T) )
x, y, w, h = cv2.boundingRect(tcorners.reshape(1,-1,2))
A = np.hstack([A, [[-x], [-y]]])
img = cv2.warpAffine(img, A, (w, h), flags=cv2.INTER_LINEAR, borderMode=cv2.BORDER_REPLICATE)
if tilt != 1.0:
s = 0.8*np.sqrt(tilt*tilt-1)
img = cv2.GaussianBlur(img, (0, 0), sigmaX=s, sigmaY=0.01)
img = cv2.resize(img, (0, 0), fx=1.0/tilt, fy=1.0, interpolation=cv2.INTER_NEAREST)
A[0] /= tilt
if phi != 0.0 or tilt != 1.0:
h, w = img.shape[:2]
mask = cv2.warpAffine(mask, A, (w, h), flags=cv2.INTER_NEAREST)
Ai = cv2.invertAffineTransform(A)
return img, mask, Ai
开发者ID:hiroponta,项目名称:PythonApplication1,代码行数:30,代码来源:asift.py
示例7: test_maskandscale
def test_maskandscale():
t = np.linspace(20, 30, 15)
t[3] = 100
tm = np.ma.masked_greater(t, 99)
fname = pjoin(TEST_DATA_PATH, 'example_2.nc')
with netcdf_file(fname, maskandscale=True) as f:
Temp = f.variables['Temperature']
assert_equal(Temp.missing_value, 9999)
assert_equal(Temp.add_offset, 20)
assert_equal(Temp.scale_factor, np.float32(0.01))
found = Temp[:].compressed()
del Temp # Remove ref to mmap, so file can be closed.
expected = np.round(tm.compressed(), 2)
assert_allclose(found, expected)
with in_tempdir():
newfname = 'ms.nc'
f = netcdf_file(newfname, 'w', maskandscale=True)
f.createDimension('Temperature', len(tm))
temp = f.createVariable('Temperature', 'i', ('Temperature',))
temp.missing_value = 9999
temp.scale_factor = 0.01
temp.add_offset = 20
temp[:] = tm
f.close()
with netcdf_file(newfname, maskandscale=True) as f:
Temp = f.variables['Temperature']
assert_equal(Temp.missing_value, 9999)
assert_equal(Temp.add_offset, 20)
assert_equal(Temp.scale_factor, np.float32(0.01))
expected = np.round(tm.compressed(), 2)
found = Temp[:].compressed()
del Temp
assert_allclose(found, expected)
开发者ID:ElDeveloper,项目名称:scipy,代码行数:35,代码来源:test_netcdf.py
示例8: ammoniawater
def ammoniawater(allligand,index,bond_dist):
D = 3.0
allligandcoods = allligand.positions
ncoods = np.zeros((1,3), dtype = float)
ncoods[0,:] = allligandcoods[index,:]
ncoods = np.float32(ncoods)
tempdist = MDAnalysis.lib.distances.distance_array(allligandcoods, ncoods)
A = np.where((tempdist < bond_dist) & (tempdist > 0.1))
mates = np.ravel_multi_index(A, tempdist.shape)
nummates = np.size(mates)
hcoods = np.zeros((3,3), dtype = float)
i = 0
for j in mates:
if allligand[j].type == 'H':
hcoods[i,:] = allligandcoods[j,:]
i = i + 1
hcoods = np.float32(hcoods)
tempvector = hcoods - ncoods
vector1 = unitvector(tempvector[0,:])
vector2 = unitvector(tempvector[1,:])
vector3 = unitvector(tempvector[2,:])
watercood = np.zeros((3,3), dtype = float)
watercood[0,:] = ncoods + (D*vector1)
watercood[1,:] = ncoods + (D*vector2)
watercood[2,:] = ncoods + (D*vector3)
return watercood
开发者ID:gregoryross,项目名称:WaterDock2.0,代码行数:33,代码来源:addwater.py
示例9: secaminewater
def secaminewater(allligand,index,bond_dist):
D = 3.0
allligandcoods = allligand.positions
ncoods = np.zeros((1,3), dtype = float)
ncoods[0,:] = allligandcoods[index,:]
ncoods = np.float32(ncoods)
tempdist = MDAnalysis.lib.distances.distance_array(allligandcoods, ncoods)
A = np.where((tempdist < bond_dist) & (tempdist > 0.1))
mates = np.ravel_multi_index(A, tempdist.shape)
nummates = np.size(mates)
hcoods = np.zeros((1,3), dtype = float)
q = 0
for j in mates:
if allligand[j].type == 'H':
hcoods[0,:] = allligandcoods[j,:]
break
watercood = np.zeros((1,3), dtype = float)
hcoods = np.float32(hcoods)
vector = unitvector(hcoods - ncoods)
watercood[0,:] = ncoods + (D * vector)
return watercood
开发者ID:gregoryross,项目名称:WaterDock2.0,代码行数:27,代码来源:addwater.py
示例10: __init__
def __init__(self, bounds, objectNum):
self.meas=[]
self.pred=[]
self.objectNum = objectNum
# self.frame = np.zeros((400,400,3), np.uint8) # drawing canvas
self.mp = np.array((2,1), np.float32) # measurement
# self.tp = np.zeros((2,1), np.float32) # tracked / prediction
self.tp = np.array([[np.float32(bounds.center_x)],[np.float32(bounds.center_y)]])
self.currentPrediction = (bounds.center_x,bounds.center_y)
# cv2.namedWindow("kalman")
# cv2.setMouseCallback("kalman",onmouse);
self.kalman = cv2.KalmanFilter(4,2)
self.kalman.measurementMatrix = np.array([[1,0,0,0],[0,1,0,0]],np.float32)
self.kalman.transitionMatrix = np.array([[1,0,1,0],[0,1,0,1],[0,0,1,0],[0,0,0,1]],np.float32)
self.kalman.processNoiseCov = np.array([[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]],np.float32) * .003
# self.kalman.processNoiseCov = np.array([[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]],np.float32) * 0.03
# APPLY KALMAN
track_x, track_y = bounds.center_x,bounds.center_y
self.meas.append( (track_x, track_y) )
for i in range(100):
self.mp = np.array([[np.float32(track_x)],[np.float32(track_y)]])
self.kalman.correct(self.mp)
self.predict()
开发者ID:Isaac-W,项目名称:CS510_Assignments,代码行数:25,代码来源:SIFT_Detection.py
示例11: child_indices
def child_indices(node):
indices[node] = numpy.float32(counter[0])
counter[0] += 1
if isinstance(node, LeafNode):
return [numpy.float32(0), numpy.float32(0)]
else:
return [indices[node.left], indices[node.right]]
开发者ID:igul222,项目名称:Marmot,代码行数:7,代码来源:trees.py
示例12: apply
def apply(self , src , mask_length , tgt):
"""
viterbi algorithm
"""
result , updates = theano.scan(
fn = self.train_step,
sequences = src,
outputs_info = [self.A_start, None] ,
non_sequences = self.A ,
n_steps = mask_length
)
# the score of best path
best_path_score = result[0][-1].max()
idx = T.argmax(result[0][-1])
#backtracking
res2 , _ = theano.scan(
fn = lambda dps , idx , idx2 : [dps[idx] , idx],
sequences = result[1][::-1],
outputs_info = [idx , idx],
n_steps = mask_length
)
# the path of best score
best_path = res2[1]
#if len(best_path) < seq_len:
# best_path.extend((seq_len - len(best_path)) * [2])
# the score of tgt path
tgt_score = self.decode(src , mask_length , tgt)
# max_margin
max_margin = T.sum(T.neq(tgt[:mask_length] , best_path))
cost = best_path_score + max_margin - tgt_score
return T.switch(T.lt(cost , T.alloc(numpy.float32(0.)))
, T.alloc(numpy.float32(0.))
, cost
),best_path
开发者ID:gumaojie,项目名称:cws_theano,代码行数:34,代码来源:models.py
示例13: test_gpuspecifyshape
def test_gpuspecifyshape():
x = cuda.shared_constructor(numpy.ones(3, dtype='float32'), 'x')
m = theano.tensor.specify_shape(x + numpy.float32(1), (3,))
f = theano.function([], updates=[(x, m * numpy.float32(2))],
mode=mode_with_gpu)
l = f.maker.fgraph.toposort()
assert not numpy.any([isinstance(x.op, cuda.HostFromGpu) for x in l])
开发者ID:Abioy,项目名称:Theano,代码行数:7,代码来源:test_opt.py
示例14: testIFD
def testIFD():
# test I
assert packet.pack('I',3) == struct.pack('<ci', b'I', 3)
assert packet.pack('I',3) != struct.pack('<ci', b'I', 4)
assert packet.unpack_stream(
io.BytesIO(struct.pack('<ci', b'I', 3))) == ('I', 3)
assert packet.unpack_stream(
io.BytesIO(struct.pack('<ci', b'I', 4))) != ('I', 3)
# test F
assert packet.pack('F',3.3) == struct.pack('<cf', b'F', 3.3)
assert packet.pack('F',3.3) != struct.pack('<cf', b'F', 4.3)
assert packet.unpack_stream(
io.BytesIO(struct.pack('<cf', b'F', numpy.float32(3.3)))) == ('F', numpy.float32(3.3))
assert packet.unpack_stream(
io.BytesIO(struct.pack('<cf', b'F', 4.3))) != ('F', 3.3)
# test D
assert packet.pack('D',3.3) == struct.pack('<cd', b'D', 3.3)
assert packet.pack('D',3.3) != struct.pack('<cd', b'D', 4.3)
assert packet.unpack_stream(
io.BytesIO(struct.pack('<cd', b'D', 3.3))) == ('D', 3.3)
assert packet.unpack_stream(
io.BytesIO(struct.pack('<cd', b'D', 4.3))) != ('D', 3.3)
开发者ID:mcdeoliveira,项目名称:beaglebone,代码行数:28,代码来源:test_packet.py
示例15: rmsprop
def rmsprop(lr, tparams, grads, inp, cost):
zipped_grads = [theano.shared(p.get_value() * numpy.float32(0.),
name='%s_grad' % k)
for k, p in tparams.iteritems()]
running_grads = [theano.shared(p.get_value() * numpy.float32(0.),
name='%s_rgrad' % k)
for k, p in tparams.iteritems()]
running_grads2 = [theano.shared(p.get_value() * numpy.float32(0.),
name='%s_rgrad2' % k)
for k, p in tparams.iteritems()]
zgup = [(zg, g) for zg, g in zip(zipped_grads, grads)]
rgup = [(rg, 0.95 * rg + 0.05 * g) for rg, g in zip(running_grads, grads)]
rg2up = [(rg2, 0.95 * rg2 + 0.05 * (g ** 2))
for rg2, g in zip(running_grads2, grads)]
f_grad_shared = theano.function(inp, cost, updates=zgup+rgup+rg2up,
profile=profile)
updir = [theano.shared(p.get_value() * numpy.float32(0.),
name='%s_updir' % k)
for k, p in tparams.iteritems()]
updir_new = [(ud, 0.9 * ud - 1e-4 * zg / tensor.sqrt(rg2 - rg ** 2 + 1e-4))
for ud, zg, rg, rg2 in zip(updir, zipped_grads, running_grads,
running_grads2)]
param_up = [(p, p + udn[1])
for p, udn in zip(itemlist(tparams), updir_new)]
f_update = theano.function([lr], [], updates=updir_new+param_up,
on_unused_input='ignore', profile=profile)
return f_grad_shared, f_update
开发者ID:G-Wang,项目名称:dl4mt-material,代码行数:31,代码来源:nmt.py
示例16: main
def main():
normalize.normalizeData('twitter_dataset.csv')
cutoff = 0.5
k = int(raw_input("Input Number of cluster:"))
start_time = time.time()
reader = getDataFromFile()
points = []
point_counter = 0
for row in reader:
points.append(getinfo(row[1:]))
point_counter = point_counter + 1
clusters = kmeans(points, k, cutoff)
#total_points ,final_centroids = clusters
cluster_per = []
end_time = time.time() - start_time
for i,c in enumerate(clusters):
count = 0
for p in c.points:
print " Cluster: ",i + 1,"\t Point :", p
count = count + 1
print "no of instance for cluster" , i + 1 ,":" ,count
cluster_per.append(np.float32(((np.float32(count) / np.float32(point_counter)) * 100)))
print "Time:" , end_time, "Seconds"
print "Number of Clusters:" , k
for idx,cp in enumerate(cluster_per):
print "cluster", idx + 1 , ":" , cp , "%"
开发者ID:PadaliaRushabh,项目名称:tweetx,代码行数:29,代码来源:kmean.py
示例17: adjust_lr
def adjust_lr(self, epoch, size, val_error_list = None):
# lr is calculated every time as a function of epoch and size
if self.config['lr_policy'] == 'step':
if epoch >=20 and epoch < 40:
self.step_idx = 1
elif epoch >=40 and epoch < 60:
self.step_idx = 2
elif epoch >=60 and epoch < 70:
self.step_idx = 3
else:
pass
tuned_base_lr = self.base_lr * 1.0/pow(10.0,self.step_idx)
if self.config['lr_policy'] == 'auto':
if epoch>5 and (val_error_list[-3] - val_error_list[-1] <
self.config['lr_adapt_threshold']):
tuned_base_lr = self.base_lr / 10.0
if self.config['train_mode'] == 'cdd':
self.shared_lr.set_value(np.float32(tuned_base_lr))
elif self.config['train_mode'] == 'avg':
self.shared_lr.set_value(np.float32(tuned_base_lr*size))
if self.verbose:
print 'Learning rate now: %.10f' % np.float32(self.shared_lr.get_value())
开发者ID:adeelzaman,项目名称:Theano-MPI,代码行数:35,代码来源:alex_net.py
示例18: update
def update(self, track_x, track_y):
# APPLY KALMAN
self.meas.append( (track_x, track_y) )
self.mp = np.array([[np.float32(track_x)],[np.float32(track_y)]])
self.kalman.correct(self.mp)
self.predict()
开发者ID:Isaac-W,项目名称:CS510_Assignments,代码行数:7,代码来源:SIFT_Detection.py
示例19: carbonylorcarboxyl
def carbonylorcarboxyl(allligand,index,bond_dist):
allligandcoods = allligand.positions
ocoods = np.zeros((1,3), dtype = float)
ocoods[0,:] = allligandcoods[index,:]
ocoods = np.float32(ocoods)
tempdist = MDAnalysis.lib.distances.distance_array(ocoods,allligandcoods)
A = np.argsort(tempdist)
temp = int(A[0,1])
Omatecood = np.zeros((1,3), dtype = float)
Omatecood[0,:] = allligandcoods[temp,:]
Omatecood = np.float32(Omatecood)
tempdist2 = MDAnalysis.lib.distances.distance_array(Omatecood, allligandcoods)
B = np.argsort(tempdist2)
B = np.delete(B,0,axis = 1)
for i in xrange(0,B.size):
if B[0,i] == index:
C = np.delete(B,i,axis = 1)
break
base1 = int(C[0,0])
base2 = int(C[0,1])
type1 = allligand[base1].type
type2 = allligand[base2].type
if type1 == 'O' or type2 == 'O':
atype = 'carboxyl'
else:
atype = 'carbonyl'
return atype
开发者ID:gregoryross,项目名称:WaterDock2.0,代码行数:34,代码来源:addwater.py
示例20: test_cublasSgemmBatched
def test_cublasSgemmBatched(self):
l, m, k, n = 11, 7, 5, 3
A = np.random.rand(l, m, k).astype(np.float32)
B = np.random.rand(l, k, n).astype(np.float32)
C_res = np.einsum('nij,njk->nik', A, B)
a_gpu = gpuarray.to_gpu(A)
b_gpu = gpuarray.to_gpu(B)
c_gpu = gpuarray.empty((l, m, n), np.float32)
alpha = np.float32(1.0)
beta = np.float32(0.0)
a_arr = bptrs(a_gpu)
b_arr = bptrs(b_gpu)
c_arr = bptrs(c_gpu)
cublas.cublasSgemmBatched(self.cublas_handle, 'n','n',
n, m, k, alpha,
b_arr.gpudata, n,
a_arr.gpudata, k,
beta, c_arr.gpudata, n, l)
assert np.allclose(C_res, c_gpu.get())
开发者ID:Brainiarc7,项目名称:scikit-cuda,代码行数:25,代码来源:test_cublas.py
注:本文中的numpy.float32函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论