• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python numpy.set_printoptions函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中numpy.set_printoptions函数的典型用法代码示例。如果您正苦于以下问题:Python set_printoptions函数的具体用法?Python set_printoptions怎么用?Python set_printoptions使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了set_printoptions函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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]
开发者ID:seama107,项目名称:phys227-final,代码行数:31,代码来源:final.py


示例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 
开发者ID:ostepok,项目名称:grass-gis-bba,代码行数:26,代码来源:i.ortho.bba.py


示例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)
开发者ID:Dialloalha,项目名称:pylayers,代码行数:7,代码来源:constraint.py


示例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)
开发者ID:andyreagan,项目名称:pysal,代码行数:7,代码来源:twosls_sp_regimes.py


示例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")
开发者ID:gringer,项目名称:bioinfscripts,代码行数:34,代码来源:porejuicer.py


示例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
开发者ID:jbriales,项目名称:rpg_vikit,代码行数:33,代码来源:align_trajectory.py


示例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:")
开发者ID:JonasWallin,项目名称:BayesFlow,代码行数:25,代码来源:test_GMM_long.py


示例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
开发者ID:jeburke,项目名称:RNA-is-awesome,代码行数:33,代码来源:SPScores.py


示例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()
开发者ID:maxikov,项目名称:smartspacedatan,代码行数:33,代码来源:k_means_load_and_cartesian_plot.py


示例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
开发者ID:jeburke,项目名称:RNA-is-awesome,代码行数:29,代码来源:SPScores.py


示例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")
开发者ID:binnisb,项目名称:mappingmicrobe16s,代码行数:27,代码来源:blast_filter.py


示例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.
开发者ID:b45ch1,项目名称:indegrator,代码行数:30,代码来源:explicit_euler.py


示例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
开发者ID:diradical,项目名称:pyscf,代码行数:35,代码来源:hf.py


示例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:")
开发者ID:JonasWallin,项目名称:BayesFlow,代码行数:29,代码来源:test_GMM_long.py


示例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)
开发者ID:jeremyn,项目名称:python-machine-learning-book,代码行数:27,代码来源:chapter_8.py


示例16: get_response_content

def get_response_content(fs):
    # make the laplacian matrix for the graph
    weight = 1 / fs.edge_length
    n = fs.nvertices
    L = np.zeros((n,n))
    # set the diagonal
    for i in range(n):
        L[i,i] = 2 * weight
    L[0,0] = weight
    L[-1,-1] = weight
    # complete the tridiagonal
    for i in range(n-1):
        L[i+1,i] = -weight
        L[i,i+1] = -weight
    # define other matrices
    L_pinv = np.linalg.pinv(L)
    HDH = -2*L_pinv
    v = np.diag(HDH)
    e = np.ones(n)
    D = HDH - (np.outer(v, e) + np.outer(e, v))/2
    # show some matrices
    out = StringIO()
    np.set_printoptions(linewidth=300)
    print >> out, 'Laplacian matrix:'
    print >> out, L
    print >> out
    print >> out, 'HDH:'
    print >> out, HDH
    print >> out
    print >> out, 'EDM:'
    print >> out, D
    print >> out
    return out.getvalue()
开发者ID:argriffing,项目名称:xgcode,代码行数:33,代码来源:20110722a.py


示例17: main

def main():
    np.set_printoptions(threshold=np.nan)
    
    feature_names = get_feature_names()
    x_train, y_train,  = get_data("training.dat")

    clf = linear_model.LinearRegression()
    clf.fit (x_train, y_train)
    
    w = clf.coef_.reshape(clf.coef_.shape[1],1) 
    y_hat_train = x_train.dot(w)

    rmse_our_train, rmse_oba_train = get_rmse(y_train, y_hat_train)
    
    x_test, y_test = get_data("test.dat")
    y_hat_test = x_test.dot(w)

    rmse_our_test, rmse_oba_test = get_rmse(y_test, y_hat_test)
 
    print "RMSE OUR Train ", rmse_our_train
    print "RMSE OBA Train ", rmse_oba_train
    print "RMSE OUR Test ", rmse_our_test
    print "RMSE OBA Test ", rmse_oba_test

    save_scatter_plot(y_train, y_hat_train, "train")
    save_scatter_plot(y_test, y_hat_test, "test")
    
    build_output_files(y_hat_train, y_hat_test, y_train, y_test)
    print_weights(w, feature_names);
    report_range(y_train)
    report_range(y_test)
开发者ID:sameersingh,项目名称:onebusaway,代码行数:31,代码来源:linear_regression.py


示例18: test_0d_arrays

    def test_0d_arrays(self):
        assert_equal(repr(np.datetime64('2005-02-25')[...]),
                     "array('2005-02-25', dtype='datetime64[D]')")

        x = np.array(1)
        np.set_printoptions(formatter={'all':lambda x: "test"})
        assert_equal(repr(x), "array(test)")
开发者ID:Juanlu001,项目名称:numpy,代码行数:7,代码来源:test_arrayprint.py


示例19: writeOVERFLOW

def writeOVERFLOW(filename, X, Y):
    f = open(filename, 'w')
    print 'Writing ', filename
   
    # Overflow requires 3 spanwise ndoes

    ni, nj = X.shape; nk = 3
    
    npy.set_printoptions( precision=16, threshold = ni )
    
    f.write('1'+'\n')
    f.write(str(ni) + ' ' + str(nj) + ' ' + str(nk) + '\n')
    Write3DArray(f,X)
    Write3DArray(f,X)
    Write3DArray(f,X)

    Z = npy.ones(X.shape)*0
    Write3DArray(f,Z)
    Z = npy.ones(X.shape)*-0.5
    Write3DArray(f,Z)
    Z = npy.ones(X.shape)*-1
    Write3DArray(f,Z)

    Write3DArray(f,Y)
    Write3DArray(f,Y)
    Write3DArray(f,Y)
               
    f.close()
开发者ID:galbramc,项目名称:HOW4,代码行数:28,代码来源:plot3d.py


示例20: train_network

def train_network(model, num_epochs = 100, minibatch_size = 256, lr = 0.01, mom = 0.9, wd = 0.0000):
    np.set_printoptions(linewidth=200)
    owl.set_device(owl.create_gpu_device(0))
    count = 0
    # load data
    (train_data, test_data) = imageio.load_mb_from_mat("mnist_all.mat", minibatch_size)
    num_test_samples = test_data[0].shape[0]
    (test_samples, test_labels) = map(lambda npdata : owl.from_nparray(npdata), test_data)
    for i in xrange(num_epochs):
        print "---Epoch #", i
        for (mb_samples, mb_labels) in train_data:
            num_samples = mb_samples.shape[0]
            data = owl.from_nparray(mb_samples).reshape([28, 28, 1, num_samples])
            label = owl.from_nparray(mb_labels)
            out, weightgrad, biasgrad = train(model, data, label)
            for k in range(len(model.weights)):
                model.weightdelta[k] = mom * model.weightdelta[k] - lr / num_samples * weightgrad[k] - wd * model.weights[k]
                model.biasdelta[k] = mom * model.biasdelta[k] - lr / num_samples * biasgrad[k]
                model.weights[k] += model.weightdelta[k]
                model.bias[k] += model.biasdelta[k]

            count = count + 1
            if (count % 1) == 0:
                print_training_accuracy(out, label, num_samples)
            if count == 100:
                sys.exit()
开发者ID:Alienfeel,项目名称:minerva,代码行数:26,代码来源:mnist_cnn.py



注:本文中的numpy.set_printoptions函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python numpy.set_string_function函数代码示例发布时间:2022-05-27
下一篇:
Python numpy.select函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap