本文整理汇总了Python中numpy.set_printoptions函数的典型用法代码示例。如果您正苦于以下问题:Python set_printoptions函数的具体用法?Python set_printoptions怎么用?Python set_printoptions使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了set_printoptions函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: findmaxima
def findmaxima(c, var = 'x'):
"""
Creates a RK-4 approximation of Rossler curve with the given c value
and returns local maxima along the x(t) curve from T0 to T
"""
T0 = 250
e = 3E-4
Rc = Rossler(c, dt=0.01, T0 = T0)
Rc.run()
if var == 'x':
var = Rc.x
elif var == 'y':
var = Rc.y
else:
var = Rc.z
#using only valuse where t > T0
initial_index = np.where(Rc.t == T0)[0][0]
#moving back 1 to get a more exact diff
usable_x = var[initial_index - 1:]
x_diff = np.diff(usable_x)
usable_x = usable_x[1:]
np.set_printoptions(threshold='nan')
critical_points = usable_x[np.abs(x_diff) < e]
return critical_points[critical_points > 0]
示例2: main
def main():
# read data from Bingo-F protocols
in_dt = InputData(BingoParser(options["bingo_data_dir"]))
phs = in_dt.GetPhotos()
pts = in_dt.GetPoints()
cam_m, distor = in_dt.GetCameras().values()[0].GetParams()
# compute relative orientations and merged them into common system
ros = RelativeOrientation(in_dt)
np.set_printoptions(precision=3, suppress=True)
#PlotScene(pts, phs)
#PlotRelOrs(pts, phs)
# performs helmert transformation into world coordinate system
HelmertTransform(pts, phs)
# run bundle block adjustment
ph_errs, pt_errs = RunBundleBlockAdjutment(in_dt, options['protocol_dir'], flags['f'])
PlotScene(pts, phs)
return
示例3: info
def info(self):
"""
"""
print '{0:4} , {1:15}, {2:5}, {3:5}, {4:7}, {5:6}, {6:8}, {7:9}'.format('type', 'p', 'value', 'std', 'runable' , 'usable' , 'obsolete' , 'evaluated')
np.set_printoptions(precision=3)
print '{0:4} , {1:15}, {2:5}, {3:5}, {4:7}, {5:6}, {6:8}, {7:9}'.format(self.type, self.p, self.value, self.std, self.runable, self.usable , self.obsolete , self.evaluated)
示例4: _test
def _test():
import doctest
start_suppress = np.get_printoptions()["suppress"]
np.set_printoptions(suppress=True)
doctest.testmod()
np.set_printoptions(suppress=start_suppress)
示例5: generate_eventdir_matrix
def generate_eventdir_matrix(fileName, header=True, direction=None):
'''write out directed event matrix from fast5, False if not present'''
try: # check to make sure the file actually exists
h5File = h5py.File(fileName, 'r')
h5File.close()
except:
return False
with h5py.File(fileName, 'r') as h5File:
rowData = get_telemetry(h5File, "000", fileName)
channel = str(rowData['channel'])
mux = str(rowData['mux'])
runID = rowData['runID']
dir = "complement" if (direction=="r") else "template"
eventLocation = "/Analyses/Basecall_1D_000/BaseCalled_%s/Events/" % (dir)
if(not eventLocation in h5File):
return False
readName = rowData['read']
sampleRate = str(int(rowData['sampleRate']))
rawStart = str(rowData['rawStart'])
outData = h5File[eventLocation]
dummy = h5File[eventLocation]['move'][0] ## hack to get order correct
numpy.set_printoptions(precision=15)
headers = h5File[eventLocation].dtype
if(header):
sys.stdout.write("runID,channel,mux,read,sampleRate,rawStart,"+",".join(headers.names)+"\n")
for line in outData:
res=[repr(x) for x in line]
# data seems to be normalised, but just in case it isn't in the future,
# here's the formula for calculation:
# pA = (raw + offset)*range/digitisation
# (using channelMeta[("offset", "range", "digitisation")])
# - might also be useful to know start_time from outMeta["start_time"]
# which should be subtracted from event/start
sys.stdout.write(",".join((runID,channel,mux,readName,sampleRate,rawStart)) + "," + ",".join(res) + "\n")
示例6: align_se3
def align_se3(model, data, precision=False):
"""Align two trajectories using the method of Horn (closed-form).
Input:
model -- first trajectory (3xn)
data -- second trajectory (3xn)
Output:
R -- rotation matrix (3x3)
t -- translation vector (3x1)
t_error -- translational error per point (1xn)
"""
if not precision:
np.set_printoptions(precision=3, suppress=True)
model_zerocentered = model - model.mean(1).reshape(model.shape[0], 1)
data_zerocentered = data - data.mean(1).reshape(data.shape[0], 1)
W = np.zeros((3, 3))
for column in range(model.shape[1]):
W += np.outer(model_zerocentered[:, column], data_zerocentered[:, column])
U, d, Vh = np.linalg.linalg.svd(W.transpose())
S = np.matrix(np.identity(3))
if np.linalg.det(U) * np.linalg.det(Vh) < 0:
S[2, 2] = -1
R = U * S * Vh
t = data.mean(1).reshape(data.shape[0], 1) - R * model.mean(1).reshape(model.shape[0], 1)
model_aligned = R * model + t
alignment_error = model_aligned - data
t_error = np.sqrt(np.sum(np.multiply(alignment_error, alignment_error), 0)).A[0]
return R, t, t_error
示例7: general_mix
def general_mix(self, mix, **kwargs):
"""
simple mix data test
"""
npr.seed(122351)
self.mix = mix(K = self.nClass,**kwargs)
self.mix.set_data(self.Y)
self.mu_sample = list()
self.sigma_sample = list()
self.p_sample = list()
for k in range(self.nClass):
self.mu_sample.append(np.zeros_like(self.Thetas[k]))
self.sigma_sample.append(np.zeros_like(self.Sigmas[k]))
self.p_sample.append(np.zeros_like(self.P[k]))
for i in range(self.sim): # @UnusedVariable
self.mix.sample()
for k in range(self.nClass):
self.mu_sample[k] += self.mix.mu[k]
self.sigma_sample[k] += self.mix.sigma[k]
self.p_sample[k] += self.mix.p[k]
np.set_printoptions(precision=2)
self.compare_class("MCMC:")
示例8: branch_PSSM
def branch_PSSM(peak_branch_df, fa_dict):
base_dict = {"A":0, "C":1, "T":2, "G":3}
nuc_prob = gc_content(fa_dict)
pos_matrix_branch = np.zeros([4,5])
counter = 0
if type(peak_branch_df) == str:
with open(peak_branch_df) as f:
for line in f:
counter += 1
seq = line.strip()
for a, base in enumerate(seq):
pos_matrix_branch[base_dict[base],a] += 1
else:
for seq in peak_branch_df['Branch seq']:
counter += 1
seq = seq[2:7]
for a, base in enumerate(seq):
pos_matrix_branch[base_dict[base],a] += 1
float_formatter = lambda x: "%.1f" % x
np.set_printoptions(formatter={'float_kind':float_formatter})
a = 0
while a < 4:
b = 0
while b < 5:
if pos_matrix_branch[a,b] == 0: pos_matrix_branch[a,b] += 1
pos_matrix_branch[a,b] = np.log2((pos_matrix_branch[a,b]/float(counter))/nuc_prob[a])
b += 1
a += 1
return pos_matrix_branch
示例9: main
def main():
numpy.set_printoptions(precision=1, linewidth=284, threshold=40, edgeitems=13)
X = []
Y = []
order = 2
coeffs = raw_readings_norm_coeffs = {"temp": 100,
"light": 100,
"humidity" : 100, "pressure": 1e5,
"audio_p2p": 100, "motion" : 1}
data_provider = dataprovider.DataProvider(order=order, debug=True,
start_time = 1379984887,
stop_time = 1379984887+3600*24*2,
device_list = ["17030002"],
eliminate_const_one=True, device_groupping="dict",
raw_readings_norm_coeffs = coeffs)
f = open("2_order_knode.p", "rb")
knode = pickle.load(f)
f.close()
for data in data_provider:
print data
t, d = data["17030002"]
X.append(t)
l = knode.label(d)[0]
Y.append(l)
plt.plot(X, Y, 'ro')
plt.show()
示例10: generate_PSSM
def generate_PSSM(seq_list, fasta_dict):
#Populate gene dictionary and build genome
genome = fasta_dict
nuc_prob = gc_content(fasta_dict)
base_dict = {"A":0, "C":1, "T":2, "G":3}
#First generate a consensus matrix for the sequence, where 1st row is A counts, second row is C, third row is T, fourth row is G.
PSSM = np.zeros([4,len(seq_list[0])])
counter = 0
for seq in seq_list:
counter += 1
for a, base in enumerate(seq):
PSSM[base_dict[base],a] += 1
float_formatter = lambda x: "%.1f" % x
np.set_printoptions(formatter={'float_kind':float_formatter})
a = 0
while a < 4:
b = 0
while b < len(seq_list[0]):
if PSSM[a,b] == 0: PSSM[a,b] += 1
PSSM[a,b] = np.log2((PSSM[a,b]/float(counter))/nuc_prob[a])
b += 1
a += 1
return PSSM
示例11: main
def main(file,N,db_file):
original_db = list(SeqIO.parse(db_file, 'fasta'))
original_db_dict = defaultdict(Bio.SeqRecord.SeqRecord)
for i in original_db:
original_db_dict[i.id] = i
np.set_printoptions(suppress=True)
with open(file) as f:
lines = f.readlines()
lines = [l.strip().split() for l in lines if l[0] != "#"]
mat = np.array([ [v[2],v[3],v[4],v[5],v[6],v[7],v[8],v[9],v[10],v[11]] for v in lines] ,dtype=float)
id = np.array([ [l[0],l[1]] for l in lines],dtype=str)
gaps = xrange(100,N-1,-1)
for i in gaps:
hit = (mat[:,0] >= i) & (mat[:,0] < i+1) &(mat[:,1] > 370)
id_result = id[hit,:]
mat_result = mat[hit,:]
np.savetxt('.'.join([file,str(i)]),np.hstack((id_result,np.asarray(mat_result,dtype='str'))),delimiter='\t',fmt='%s' )
for result in set(id_result[:,1]):
try:
del original_db_dict[result]
except:
1
SeqIO.write(original_db_dict.values(), "%s.%s" %(db_file,i), "fasta")
示例12: fo_reverse
def fo_reverse(self, xs_bar):
numpy.set_printoptions(precision=None, threshold=None, edgeitems=None, linewidth=200, suppress=None, nanstr=None, infstr=None, formatter=None)
self.xs_bar = xs_bar.copy()
self.x0_bar = numpy.zeros(self.x0.shape)
self.f_bar = numpy.zeros(self.f.shape)
self.p_bar = numpy.zeros(self.p.shape)
self.q_bar = numpy.zeros(self.q.shape)
self.u_bar = numpy.zeros(self.u.shape)
for i in range(self.M-1)[::-1]:
h = self.ts[i+1] - self.ts[i]
self.update_u(i)
self.xs_bar[i,:] += self.xs_bar[i + 1, :]
self.f_bar[:] = h*self.xs_bar[i+1, :]
self.backend.ffcn_bar(self.ts[i:i+1],
self.xs[i, :], self.xs_bar[i,:],
self.f, self.f_bar,
self.p, self.p_bar,
self.u, self.u_bar)
self.xs_bar[i + 1, :] = 0
self.update_u_bar(i)
self.x0_bar[:] += self.xs_bar[0, :]
self.xs_bar[0, :] = 0.
示例13: get_occ
def get_occ(self, mo_energy=None, mo_coeff=None):
'''Label the occupancies for each orbital
Kwargs:
mo_energy : 1D ndarray
Obital energies
mo_coeff : 2D ndarray
Obital coefficients
Examples:
>>> from pyscf import gto, scf
>>> mol = gto.M(atom='H 0 0 0; F 0 0 1.1')
>>> mf = scf.hf.SCF(mol)
>>> mf.get_occ(numpy.arange(mol.nao_nr()))
array([2, 2, 2, 2, 2, 0])
'''
if mo_energy is None: mo_energy = self.mo_energy
mo_occ = numpy.zeros_like(mo_energy)
nocc = self.mol.nelectron // 2
mo_occ[:nocc] = 2
if nocc < mo_occ.size:
logger.info(self, 'HOMO = %.12g, LUMO = %.12g,',
mo_energy[nocc-1], mo_energy[nocc])
if mo_energy[nocc-1]+1e-3 > mo_energy[nocc]:
logger.warn(self, '!! HOMO %.12g == LUMO %.12g',
mo_energy[nocc-1], mo_energy[nocc])
else:
logger.info(self, 'HOMO = %.12g,', mo_energy[nocc-1])
if self.verbose >= logger.DEBUG:
numpy.set_printoptions(threshold=len(mo_energy))
logger.debug(self, ' mo_energy = %s', mo_energy)
numpy.set_printoptions()
return mo_occ
示例14: general_mix_AMCMC
def general_mix_AMCMC(self, mix, **kwargs):
"""
simple mix data test using AMCMC
"""
self.mix = mix(K = self.nClass,**kwargs)
self.mix.set_data(self.Y)
for i in range(100):#np.int(np.ceil(0.1*self.sim))): # @UnusedVariable
self.mix.sample()
self.mu_sample = list()
self.sigma_sample = list()
self.p_sample = list()
for k in range(self.nClass):
self.mu_sample.append(np.zeros_like(self.Thetas[k]))
self.sigma_sample.append(np.zeros_like(self.Sigmas[k]))
self.p_sample.append(np.zeros_like(self.P[k]))
self.mix.set_AMCMC(1200)
sim_m = 2.
for i in range(np.int(np.ceil(sim_m*self.sim))): # @UnusedVariable
self.mix.sample()
for k in range(self.nClass):
self.mu_sample[k] += self.mix.mu[k]/sim_m
self.sigma_sample[k] += self.mix.sigma[k]/sim_m
self.p_sample[k] += self.mix.p[k] /sim_m
np.set_printoptions(precision=2)
self.compare_class("AMCMC:")
示例15: work_with_simple_bag_of_words
def work_with_simple_bag_of_words():
count = CountVectorizer()
docs = np.array([
'The sun is shining',
'The weather is sweet',
'The sun is shining and the weather is sweet',
])
bag = count.fit_transform(docs)
print(count.vocabulary_)
print(bag.toarray())
np.set_printoptions(precision=2)
tfidf = TfidfTransformer(use_idf=True, norm='l2', smooth_idf=True)
print(tfidf.fit_transform(bag).toarray())
tf_is = 2
n_docs = 3
idf_is = np.log((n_docs+1) / (3+1))
tfidf_is = tf_is * (idf_is + 1)
print("tf-idf of term 'is' = %.2f" % tfidf_is)
tfidf = TfidfTransformer(use_idf=True, norm=None, smooth_idf=True)
raw_tfidf = tfidf.fit_transform(bag).toarray()[-1]
print(raw_tfidf)
l2_tfidf = raw_tfidf / np.sqrt(np.sum(raw_tfidf**2))
print(l2_tfidf)