本文整理汇总了Python中numpy.put函数的典型用法代码示例。如果您正苦于以下问题:Python put函数的具体用法?Python put怎么用?Python put使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了put函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _select_mono
def _select_mono(self, chunk):
keep_monomorphic = self.keep_monomorphic
gts = chunk[GT_FIELD]
if is_dataset(gts):
gts = gts[:]
shape = gts.shape
# we count how many different alleles are per row
# we do it adding a complex part to each number. The complex part is
# related with the row. Then we use unique
weight = 1j * numpy.arange(0, shape[0])
weight = numpy.repeat(weight, shape[1] * shape[2]).reshape(shape)
b = gts + weight
_, ind = numpy.unique(b, return_index=True)
b = numpy.zeros_like(gts)
c = numpy.ones_like(gts)
numpy.put(b, ind, c.flat[ind])
c = numpy.sum(b, axis=(2, 1))
# we remove the missing values from the count
rows_with_missing = numpy.any(gts == -1, axis=(1, 2))
c -= rows_with_missing
if keep_monomorphic:
selected_rows = (c <= 2)
else:
selected_rows = (c == 2)
return selected_rows
开发者ID:JoseBlanca,项目名称:variation,代码行数:30,代码来源:filters.py
示例2: _inverse_permutation
def _inverse_permutation(p):
"""inverse permutation p"""
n = p.size
s = np.zeros(n, dtype=np.int32)
i = np.arange(n, dtype=np.int32)
np.put(s, p, i) # s[p] = i
return s
开发者ID:0664j35t3r,项目名称:scikit-learn,代码行数:7,代码来源:rcv1.py
示例3: basic_mutation
def basic_mutation(self_individual, individual):
"""Performs a basic mutation where one value in the chromosome is replaced by another valid value."""
idx = numpy.random.randint(0, len(individual.genotype))
value = numpy.random.uniform(low=-100.0, high=100.0)
numpy.put(individual.genotype, [idx], [value])
individual.fitness = individual.fitness_evaluator.evaluate(individual)
return individual
开发者ID:fberanizo,项目名称:sin5006,代码行数:7,代码来源:individual_factory.py
示例4: _process
def _process(self, X, column, model_class):
# Remove values that are in mask
mask = np.array(self._get_mask(X)[:, column].T)[0]
mask_indices = np.where(mask==True)[0]
X_data = np.delete(X, mask_indices, 0)
# Instantiate the model
model = model_class()
# Slice out the column to predict and delete the column.
y_data = X[:, column]
X_data = np.delete(X_data, column, 1)
# Split training and test data
X_train, X_test, y_train, y_test = train_test_split(X_data, y_data, test_size=0.33, random_state=42)
# Fit the model
model.fit(X_train, y_train)
# Score the model
scores = model.score(X_test, y_test)
# Predict missing vars
X_predict = np.delete(X, column, 1)
y = model.predict(X_predict)
# Replace values in X with their predictions
predict_indices = np.where(mask==False)[0]
np.put(X, predict_indicies, np.take(y, predict_indices))
# Return model and scores
return (model, scores)
开发者ID:Ouwen,项目名称:scikit-mice,代码行数:32,代码来源:skmice.py
示例5: getPattern
def getPattern(self, idx, sparseBinaryForm=False, cat=None):
"""Return a training pattern either by index or category number
Parameters:
------------------------------------------------------------------------
idx: Index of the training pattern
sparseBinaryForm: If true, return only a list of the non-zeros in the
training pattern
cat: If not None, get the first pattern belonging to category
cat. If this is specified, idx must be None
"""
if cat is not None:
assert idx is None
idx = self._categoryList.index(cat)
if not self.useSparseMemory:
pattern = self._Memory[idx]
if sparseBinaryForm:
pattern = pattern.nonzero()[0]
else:
(nz, values) = self._Memory.rowNonZeros(idx)
if not sparseBinaryForm:
pattern = numpy.zeros(self._Memory.nCols())
numpy.put(pattern, nz, 1)
else:
pattern = nz
return pattern
开发者ID:AlexWD,项目名称:nupic,代码行数:31,代码来源:KNNClassifier.py
示例6: fit_final_model
def fit_final_model(self):
final_model = RandomForestClassifier(n_estimators = self.ntrees, criterion = self.criterion)
ws = np.zeros(len(self.y))
np.put(ws, np.nonzero(self.y == 1)[0], self.params["weight"])
np.put(ws, np.nonzero(self.y == 0)[0], 1 - self.params["weight"])
final_model.fit(self.X[:, self.params["var_subset"]], self.y, sample_weight = ws)
return final_model
开发者ID:btcross26,项目名称:Data-Mining-Capstone-Project,代码行数:7,代码来源:RandomForestAnalysis.py
示例7: sortedlist
def sortedlist(leng):
counter=0
aray=np.random.randint(1,1000,leng)
for i in range(0,leng):
ini=0
ini1=1
for i in aray:
i2=aray[ini1]
if i>i2:
np.put(aray,ini1,i)
np.put(aray,ini,i2)
counter=counter+1
print(aray)
ini1=ini1+1
ini=ini+1
if ini1==len(aray):
break
else:
ini1=ini1+1
ini=ini+1
if ini1==len(aray):
break
print"the number of shifts that occured are: ",counter-1
return(aray)
开发者ID:AIBadGuy,项目名称:List-Sort,代码行数:25,代码来源:Sort+Random+List.py
示例8: __init__
def __init__(self, data) :
if type(data) == type('') :
print 'file name:', data
data = datafunc.PyVectorDataSet(data, idColumn = 0, headerRow = True, hint = 'csv')
self.data = data
self.idDict = misc.list2dict(data.labels.patternID,
range(len(data)))
print numpy.shape(data.X)
self.mean = numpy.mean(data.X, 1)
self.std = std(data.X, 1)
eps = 1e-5
I = numpy.nonzero(numpy.less(self.std, eps))[0]
print 'num zeros:',len(I)
numpy.put(self.std, I, 1)
self.numCorrelations = 10000
correlations = numpy.zeros(self.numCorrelations, numpy.float)
for i in range(self.numCorrelations) :
i1 = random.randrange(0, len(data))
i2 = random.randrange(0, len(data))
correlations[i] = self._corrcoef(i1, i2)
self.meanCorrelation = numpy.mean(correlations)
self.numCorrelations = 1000
开发者ID:bpartridge,项目名称:PyML,代码行数:27,代码来源:preproc.py
示例9: expand
def expand( self, prof, mask, default ):
"""
Expand profile to have a value also for masked positions.
:param prof: input profile
:type prof: list OR array
:param mask: atom mask
:type mask: [int]
:param default: default value
:type default: any
:return: profile
:rtype: list OR array
"""
if mask is not None:
## optimized variant for arrays
if isinstance( prof, N.ndarray ):
p = N.resize( prof, (len(mask), ) )
p[:] = default
N.put( p, N.nonzero( mask )[0], prof )
return p
p = [ default ] * len( mask )
prof.reverse()
for i in N.nonzero( mask )[0]:
p[i] = prof.pop()
return p
return prof
开发者ID:graik,项目名称:biskit,代码行数:30,代码来源:profileCollection.py
示例10: shift
def shift(x):
x_shape = np.shape(x)
total_elements = x_shape[0] * x_shape[1]
elements_to_roll = total_elements - (x_shape[1] * time_step)
x = np.roll(AA(x, dtype=PRECISION_TO_TYPE[precision]), elements_to_roll)
np.put(x, range(elements_to_roll, total_elements), default_value)
return x
开发者ID:1132520084,项目名称:CNTK,代码行数:7,代码来源:recurrent_test.py
示例11: _untransform_params
def _untransform_params(self, x):
"""
The transformation required for _set_params_transformed.
This moves the vector x seen by the optimiser (unconstrained) to the
valid parameter vector seen by the model
Note:
- This function is separate from _set_params_transformed for downstream flexibility
"""
# work out how many places are fixed, and where they are. tricky logic!
fix_places = self.fixed_indices + [t[1:] for t in self.tied_indices]
if len(fix_places):
fix_places = np.hstack(fix_places)
Nfix_places = fix_places.size
else:
Nfix_places = 0
free_places = np.setdiff1d(np.arange(Nfix_places + x.size, dtype=np.int), fix_places)
# put the models values in the vector xx
xx = np.zeros(Nfix_places + free_places.size, dtype=np.float64)
xx[free_places] = x
[np.put(xx, i, v) for i, v in zip(self.fixed_indices, self.fixed_values)]
[np.put(xx, i, v) for i, v in [(t[1:], xx[t[0]]) for t in self.tied_indices] ]
[np.put(xx, i, t.f(xx[i])) for i, t in zip(self.constrained_indices, self.constraints)]
if hasattr(self, 'debug'):
stop # @UndefinedVariable
return xx
开发者ID:Dalar,项目名称:GPy,代码行数:32,代码来源:parameterized.py
示例12: _add_ids
def _add_ids(self, ids):
n = len(ids)
if n == 0:
return
id_max = max(ids)
id_max_old = len(self._inds)-1
n_array_old = len(self)
ids_existing = np.take(ids, np.flatnonzero(np.less(ids, id_max_old)))
# print ' ids',ids,'id_max_old',id_max_old,'ids_existing',ids_existing
# check here if ids are still available
# if np.sometrue( np.not_equal( np.take(self._inds, ids_existing), -1) ):
# print 'WARNING in create_ids: some ids already in use',ids_existing
# return np.zeros(0,int)
# extend index map with -1 as necessary
if id_max > id_max_old:
# print 'ext',-1*ones(id_max-id_max_old)
self._inds = np.concatenate((self._inds, -1*np.ones(id_max-id_max_old, int)))
# assign n new indexes to new ids
ind_new = np.arange(n_array_old, n_array_old+n, dtype=np.int32)
# print 'ind_new',ind_new
np.put(self._inds, ids, ind_new)
# print ' concat ids..',self._ids,ids
self._ids = np.concatenate((self._ids, ids))
开发者ID:behrisch,项目名称:sumo,代码行数:30,代码来源:arrayman.py
示例13: testAntisymmetric
def testAntisymmetric(matrix):
size = matrix.shape
if size[0] != size [1]:
return False
if size[0] == size[1]:
inputArray = numpy.array(matrix)
transposeArray = inputArray.T
transposeMatrix = numpy.matrix(transposeArray)
identityArray = numpy.identity(size[0])
identityMatrix = numpy.matrix(identityArray)
finalProduct = numpy.arange(size[0] ** 2)
topVal = size[0] ** 2
counter = 0
while (counter < topVal):
replaceVal = finalProduct.item(counter)
if matrix.item(counter) == 1 and transposeMatrix.item(counter) == 1:
numpy.put(finalProduct, [replaceVal], [1])
else:
numpy.put(finalProduct, [replaceVal], [0])
counter += 1
finalMatrix = numpy.matrix(finalProduct)
if lessThanOrEqual(finalMatrix, identityMatrix, size[0]):
return True
return False
开发者ID:piresjo,项目名称:Mathematical-Relations-Library,代码行数:29,代码来源:Relations.py
示例14: python_metropolis
def python_metropolis(self):
"""Implentation of the Metropolis alogrithm."""
energy = cy_potts_model.calculate_lattice_energy(self.lattice, self.lattice_size, self.bond_energy)
magnetization = self.potts_order_parameter()
for t in range(self.sweeps):
# Measurement every sweep.
np.put(self.energy_history, t, energy)
np.put(self.magnetization_history, t, magnetization)
for k in range(self.lattice_size**2):
states = [0, 1, 2]
# Pick a random location on the lattice.
rand_y = np.random.randint(0, self.lattice_size)
rand_x = np.random.randint(0, self.lattice_size)
spin = self.lattice[rand_y, rand_x] # Get spin at the random location.
# Remove the state that the spin at the random location currently occupies.
states.remove(spin)
temp_lattice = copy.deepcopy(self.lattice)
random_new_spin = np.random.choice(states)
temp_lattice[rand_y, rand_x] = random_new_spin
assert temp_lattice[rand_y, rand_x] != self.lattice[rand_y, rand_x]
new_energy = cy_potts_model.calculate_lattice_energy(temp_lattice, self.lattice_size, self.bond_energy)
energy_delta = new_energy - energy
# Energy may always be lowered.
if energy_delta <= 0:
acceptance_probability = 1
# Energy is increased with probability proportional to Boltzmann distribution.
else:
acceptance_probability = np.exp(-self.beta * energy_delta)
if np.random.random() <= acceptance_probability:
# Flip the spin and change the energy.
self.lattice[rand_y, rand_x] = random_new_spin
energy += energy_delta
magnetization = self.potts_order_parameter()
开发者ID:teunzwart,项目名称:bachelor-project,代码行数:35,代码来源:potts_model.py
示例15: tip_distances
def tip_distances(a, bound_indices, tip_indices):
"""Sets each tip to its distance from the root."""
for i, s in bound_indices:
i += s
mask = zeros(len(a))
put(mask, tip_indices, 1)
a *= mask[:,newaxis]
开发者ID:GavinHuttley,项目名称:pycogent,代码行数:7,代码来源:fast_tree.py
示例16: intersect
def intersect(self, spec):
"""Intersect with the region specification.
'spec' is a region specification of the form defined in the grid module.
Returns (mask, indexspecs) where
'mask' is the mask of the result grid AFTER self and region spec are interested.
'indexspecs' is a dictionary of index specifications suitable for slicing a
variable with the given grid.
"""
ncell = self.shape
index = self.getIndex()
latspec = spec[CoordTypeToLoc[LatitudeType]]
lonspec = spec[CoordTypeToLoc[LongitudeType]]
latlin = numpy.ma.filled(self._lataxis_)
lonlin = numpy.ma.filled(self._lonaxis_)
lonlin = numpy.ma.where(numpy.ma.greater_equal(lonlin,360.0), lonlin-360.0, lonlin)
points = bindex.intersectHorizontalGrid(latspec, lonspec, latlin, lonlin, index)
if len(points)==0:
raise CDMSError, 'No data in the specified region, longitude=%s, latitude=%s'%(`lonspec`, `latspec`)
fullmask = numpy.ones(ncell)
numpy.put(fullmask, points, 0)
imin, imax = (min(points), max(points)+1)
submask = fullmask[imin:imax]
cellid = self.getAxis(0).id
indexspecs = {cellid:slice(imin,imax)}
return submask, indexspecs
开发者ID:AZed,项目名称:uvcdat,代码行数:32,代码来源:gengrid.py
示例17: cluster_sanity
def cluster_sanity(sres):
def clusters_intersect(c1, c2):
s1 = set( c1.voxels )
s2 = set( c2.voxels )
return len(s1.intersection(s2)) > 0
mn_pt = 1e10
mx_nt = -1e10
g, m = calc_grid_and_map(sres.vox_idx)
img = np.zeros(g)
for i, clist in enumerate((sres.ptail_clusters, sres.ntail_clusters)):
for t in xrange(sres.t.shape[1]):
for f in xrange(sres.t.shape[2]):
np.put(img, m, sres.t[:,t,f])
c_tf = clist[t][f]
for c in c_tf:
cvals = np.take(img, c.voxels)
if i==1 and cvals.max() > mx_nt:
mx_nt = cvals.max()
if i==0 and cvals.min() < mn_pt:
mn_pt = cvals.min()
if len(c_tf) > 1:
for c1, c2 in zip(c_tf[:-1], c_tf[1:]):
assert not clusters_intersect(c1, c2), \
'Cluster intersection at tf=(%d,%d)'%(t,f)
print 'estimated ntail cutoff: %1.3f, estimated ptail cutoff: %1.3f'%(mx_nt, mn_pt)
开发者ID:christandiono,项目名称:nutmeg-py,代码行数:28,代码来源:test_tfstats_results.py
示例18: test_get_strain_state_dict
def test_get_strain_state_dict(self):
strain_inds = [(0,), (1,), (2,), (1, 3), (1, 2, 3)]
vecs = {}
strain_states = []
for strain_ind in strain_inds:
ss = np.zeros(6)
np.put(ss, strain_ind, 1)
strain_states.append(tuple(ss))
vec = np.zeros((4, 6))
rand_values = np.random.uniform(0.1, 1, 4)
for i in strain_ind:
vec[:, i] = rand_values
vecs[strain_ind] = vec
all_strains = [Strain.from_voigt(v).zeroed() for vec in vecs.values()
for v in vec]
random.shuffle(all_strains)
all_stresses = [Stress.from_voigt(np.random.random(6)).zeroed()
for s in all_strains]
strain_dict = {k.tostring():v for k,v in zip(all_strains, all_stresses)}
ss_dict = get_strain_state_dict(all_strains, all_stresses, add_eq=False)
# Check length of ss_dict
self.assertEqual(len(strain_inds), len(ss_dict))
# Check sets of strain states are correct
self.assertEqual(set(strain_states), set(ss_dict.keys()))
for strain_state, data in ss_dict.items():
# Check correspondence of strains/stresses
for strain, stress in zip(data["strains"], data["stresses"]):
self.assertArrayAlmostEqual(Stress.from_voigt(stress),
strain_dict[Strain.from_voigt(strain).tostring()])
开发者ID:czhengsci,项目名称:pymatgen,代码行数:29,代码来源:test_elastic.py
示例19: koskinon
def koskinon(n):
flags = resize((0,1,0,0,0,1), (n**2,))
put(flags, (0,2,3), 1)
for i in arange(5,n,2):
if flags[i]:
flags[i*i::i] = 0
return flatnonzero(flags)[2:]
开发者ID:bytemask,项目名称:solutions,代码行数:7,代码来源:23.py
示例20: optimizer_array
def optimizer_array(self, p):
"""
Make sure the optimizer copy does not get touched, thus, we only want to
set the values *inside* not the array itself.
Also we want to update param_array in here.
"""
f = None
if self.has_parent() and self.constraints[__fixed__].size != 0:
f = np.ones(self.size).astype(bool)
f[self.constraints[__fixed__]] = FIXED
elif self._has_fixes():
f = self._fixes_
if f is None:
self.param_array.flat = p
[np.put(self.param_array, ind, c.f(self.param_array.flat[ind]))
#py3 fix
#for c, ind in self.constraints.iteritems() if c != __fixed__]
for c, ind in self.constraints.items() if c != __fixed__]
else:
self.param_array.flat[f] = p
[np.put(self.param_array, ind[f[ind]], c.f(self.param_array.flat[ind[f[ind]]]))
#py3 fix
#for c, ind in self.constraints.iteritems() if c != __fixed__]
for c, ind in self.constraints.items() if c != __fixed__]
#self._highest_parent_.tie.propagate_val()
self._optimizer_copy_transformed = False
self.trigger_update()
开发者ID:sods,项目名称:paramz,代码行数:29,代码来源:parameter_core.py
注:本文中的numpy.put函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论