当前位置: 首页>>代码示例>>Python>>正文


Python scipy.arange方法代码示例

本文整理汇总了Python中scipy.arange方法的典型用法代码示例。如果您正苦于以下问题:Python scipy.arange方法的具体用法?Python scipy.arange怎么用?Python scipy.arange使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在scipy的用法示例。


在下文中一共展示了scipy.arange方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: compare_solutions

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import arange [as 别名]
def compare_solutions(A,B,m):
    n = A.shape[0]

    numpy.random.seed(0)

    V = rand(n,m)
    X = linalg.orth(V)

    eigs,vecs = lobpcg(A, X, B=B, tol=1e-5, maxiter=30)
    eigs.sort()

    #w,v = symeig(A,B)
    w,v = eig(A,b=B)
    w.sort()

    assert_almost_equal(w[:int(m/2)],eigs[:int(m/2)],decimal=2)

    #from pylab import plot, show, legend, xlabel, ylabel
    #plot(arange(0,len(w[:m])),w[:m],'bx',label='Results by symeig')
    #plot(arange(0,len(eigs)),eigs,'r+',label='Results by lobpcg')
    #legend()
    #xlabel(r'Eigenvalue $i$')
    #ylabel(r'$\lambda_i$')
    #show() 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:26,代码来源:test_lobpcg.py

示例2: test_fetch_one_column

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import arange [as 别名]
def test_fetch_one_column(tmpdata):
    _urlopen_ref = datasets.mldata.urlopen
    try:
        dataname = 'onecol'
        # create fake data set in cache
        x = sp.arange(6).reshape(2, 3)
        datasets.mldata.urlopen = mock_mldata_urlopen({dataname: {'x': x}})

        dset = fetch_mldata(dataname, data_home=tmpdata)
        for n in ["COL_NAMES", "DESCR", "data"]:
            assert_in(n, dset)
        assert_not_in("target", dset)

        assert_equal(dset.data.shape, (2, 3))
        assert_array_equal(dset.data, x)

        # transposing the data array
        dset = fetch_mldata(dataname, transpose_data=False, data_home=tmpdata)
        assert_equal(dset.data.shape, (3, 2))
    finally:
        datasets.mldata.urlopen = _urlopen_ref 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:23,代码来源:test_mldata.py

示例3: _plotFMeasures

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import arange [as 别名]
def _plotFMeasures(fstepsize=.1,  stepsize=0.0005, start = 0.0, end = 1.0):
    """Plots 10 fmeasure Curves into the current canvas."""
    p = sc.arange(start, end, stepsize)[1:]
    for f in sc.arange(0., 1., fstepsize)[1:]:
        points = [(x, _fmeasureCurve(f, x)) for x in p
                  if 0 < _fmeasureCurve(f, x) <= 1.5]
        try:
            xs, ys = zip(*points)
            curve, = pl.plot(xs, ys, "--", color="gray", linewidth=0.8)  # , label=r"$f=%.1f$"%f) # exclude labels, for legend
            # bad hack:
            # gets the 10th last datapoint, from that goes a bit to the left, and a bit down
            datapoint_x_loc = int(len(xs)/2)
            datapoint_y_loc = int(len(ys)/2)
            # x_left = 0.05
            # y_left = 0.035
            x_left = 0.035
            y_left = -0.02
            pl.annotate(r"$f=%.1f$" % f, xy=(xs[datapoint_x_loc], ys[datapoint_y_loc]), xytext=(xs[datapoint_x_loc] - x_left, ys[datapoint_y_loc] - y_left), size="small", color="gray")
        except Exception as e:
            print e 

#colors = "gcmbbbrrryk"
#colors = "yyybbbrrrckgm"  # 7 is a prime, so we'll loop over all combinations of colors and markers, when zipping their cycles 
开发者ID:zhenv5,项目名称:breaking_cycles_in_noisy_hierarchies,代码行数:25,代码来源:plot_recallPrecision.py

示例4: regresionCurve

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import arange [as 别名]
def regresionCurve(self):
        dlg = Plot(accept=True)
        x = self.curvaDestilacion.column(0)
        T = self.curvaDestilacion.column(1, Temperature)
        dlg.addData(x, T, color="black", ls="None", marker="s", mfc="red")
        parameters, r2 = curve_Predicted(x, T)
        xi = arange(0, 1, 0.01)
        Ti = [_Tb_Predicted(parameters, x_i) for x_i in xi]
        dlg.addData(xi, Ti, color="black", lw=0.5)

        # Add equation formula to plot
        txt = r"$\frac{T-T_{o}}{T_{o}}=\left[\frac{A}{B}\ln\left(\frac{1}{1-x}"
        txt += r"\right)\right]^{1/B}$"
        To = Temperature(parameters[0])
        txt2 = "\n\n\n$T_o=%s$" % To.str
        txt2 += "\n$A=%0.4f$" % parameters[1]
        txt2 += "\n$B=%0.4f$" % parameters[2]
        txt2 += "\n$r^2=%0.6f$" % r2
        dlg.plot.ax.text(0, T[-1], txt, size="14", va="top", ha="left")
        dlg.plot.ax.text(0, T[-1], txt2, size="10", va="top", ha="left")
        if dlg.exec_():
            self.curveParameters = parameters
            self.checkStatusCurve() 
开发者ID:jjgomera,项目名称:pychemqt,代码行数:25,代码来源:petro.py

示例5: coupling_optim

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import arange [as 别名]
def coupling_optim(y,t):
	creation=s.zeros(n_bin)
	destruction=s.zeros(n_bin)
	#now I try to rewrite this in a more optimized way
	destruction = -s.dot(s.transpose(kernel),y)*y #much more concise way to express\
	#the destruction of k-mers 
	kyn = kernel*y[:,s.newaxis]*y[s.newaxis,:]
	for k in xrange(n_bin):
		creation[k] = s.sum(kyn[s.arange(k),k-s.arange(k)-1])
	creation=0.5*creation
	out=creation+destruction
	return out


#Now I go for the optimal optimization of the chi_{i,j,k} coefficients used by Garrick for
# dealing with a non-uniform grid. 
开发者ID:ActiveState,项目名称:code,代码行数:18,代码来源:recipe-576547.py

示例6: test_SIS_compact_pairwise

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import arange [as 别名]
def test_SIS_compact_pairwise(self):
        print("testing SIS_compact_pairwise")
        EoN.EoNError('changing order of arguments')
        Sk0 = scipy.arange(100) * 100
        Ik0 = scipy.arange(100)
        SI0 = Ik0.dot(scipy.arange(100))
        SS0 = Sk0.dot(scipy.arange(100)) - SI0
        II0 = 0
        tau = 0.1
        gamma = 0.3
        t, S, I = EoN.SIS_compact_pairwise(Sk0, Ik0, SI0, SS0, II0, tau, gamma, tmax=5)
        print("plotting SIS_compact_pairwise")
        plt.clf()
        plt.plot(t, S)
        plt.plot(t, I)
        plt.savefig('SIS_compact_pairwise') 
开发者ID:springer-math,项目名称:Mathematics-of-Epidemics-on-Networks,代码行数:18,代码来源:test_from_joel.py

示例7: test_SIR_compact_pairwise

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import arange [as 别名]
def test_SIR_compact_pairwise(self):
        EoN.EoNError('changing order of arguments')
        print("testing SIR_compact_pairwise")
        Sk0 = scipy.arange(100) * 100
        I0 = sum(scipy.arange(100))
        R0 = 0
        SI0 = 1000
        SS0 = Sk0.dot(scipy.arange(100)) - SI0
        tau = 0.1
        gamma = 0.3
        t, S, I, R = EoN.SIR_compact_pairwise(Sk0, I0, R0, SI0, SS0, tau, gamma, tmax=5)
        print("plotting SIR_compact_pairwise")
        plt.clf()
        plt.plot(t, S)
        plt.plot(t, I)
        plt.plot(t, R)
        plt.savefig('SIR_compact_pairwise') 
开发者ID:springer-math,项目名称:Mathematics-of-Epidemics-on-Networks,代码行数:19,代码来源:test_from_joel.py

示例8: up_and_out_call

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import arange [as 别名]
def up_and_out_call(s0,x,T,r,sigma,n_simulation,barrier):
    n_steps=100. 
    dt=T/n_steps 
    total=0 
    for j in sp.arange(0, n_simulation): 
        sT=s0 
        out=False
        for i in range(0,int(n_steps)): 
            e=sp.random.normal() 
            sT*=sp.exp((r-0.5*sigma*sigma)*dt+sigma*e*sp.sqrt(dt)) 
            if sT>barrier: 
               out=True 
        if out==False: 
            total+=bsCall(s0,x,T,r,sigma) 
    return total/n_simulation 
# 
开发者ID:PacktPublishing,项目名称:Python-for-Finance-Second-Edition,代码行数:18,代码来源:c12_19_up_and_out_call.py

示例9: KMV_f

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import arange [as 别名]
def KMV_f(E,D,T,r,sigmaE):
    n=10000
    m=2000
    diffOld=1e6     # a very big number
    for i in sp.arange(1,10):
        for j in sp.arange(1,m):
            A=E+D/2+i*D/n
            sigmaA=0.05+j*(1.0-0.001)/m
            d1 = (log(A/D)+(r+sigmaA*sigmaA/2.)*T)/(sigmaA*sqrt(T))
            d2 = d1-sigmaA*sqrt(T)
            diff4E= (A*N(d1)-D*exp(-r*T)*N(d2)-E)/A  # scale by assets
            diff4A= A/E*N(d1)*sigmaA-sigmaE          # a small number already
            diffNew=abs(diff4E)+abs(diff4A)
            if diffNew<diffOld:
               diffOld=diffNew
               output=(round(A,2),round(sigmaA,4),round(diffNew,5))
    return output
# 
开发者ID:PacktPublishing,项目名称:Python-for-Finance-Second-Edition,代码行数:20,代码来源:c13_08_KMF_function.py

示例10: extend

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import arange [as 别名]
def extend(self, extracted_features):
    # This method reads the pkl files in a folder and adds them to the 
    # existing data for processing in the TCData class.


    (data, labels, feature_string, width, height, winsize, nbins) = extracted_features
    npixels = width * height

    xlabel = 'Grayscale intensity'
    ylabel = 'Probability'
    xvals  = scipy.arange(self.data.shape[0]).reshape(-1,1)
    self.data       = N.concatenate((self.data, data),axis=1) 
    self.width      = N.append(self.width, width)
    self.height     = N.append(self.height, height)
    self.xvals      = N.append(self.xvals, xvals)
    self.labels.extend(labels)
    
    self.img_label_split.extend([len(self.labels)])
    self.data_split.extend([self.data.shape[1]]) 
开发者ID:wkiri,项目名称:DEMUD,代码行数:21,代码来源:dataset_navcam.py

示例11: test_fetch_one_column

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import arange [as 别名]
def test_fetch_one_column():
    _urlopen_ref = datasets.mldata.urlopen
    try:
        dataname = 'onecol'
        # create fake data set in cache
        x = sp.arange(6).reshape(2, 3)
        datasets.mldata.urlopen = mock_mldata_urlopen({dataname: {'x': x}})

        dset = fetch_mldata(dataname, data_home=tmpdir)
        for n in ["COL_NAMES", "DESCR", "data"]:
            assert_in(n, dset)
        assert_not_in("target", dset)

        assert_equal(dset.data.shape, (2, 3))
        assert_array_equal(dset.data, x)

        # transposing the data array
        dset = fetch_mldata(dataname, transpose_data=False, data_home=tmpdir)
        assert_equal(dset.data.shape, (3, 2))
    finally:
        datasets.mldata.urlopen = _urlopen_ref 
开发者ID:alvarobartt,项目名称:twitter-stock-recommendation,代码行数:23,代码来源:test_mldata.py

示例12: xy_v_u

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import arange [as 别名]
def xy_v_u(self, v, u):
        """
        give x(v,u), y(v,u)
        """
        x_start = self.nomo_block.grid_box.x_left
        x_stop = self.nomo_block.grid_box.x_right
        if x_start > x_stop:  # should no be
            x_start, x_stop = x_stop, x_start
        # x_init=(x_start+x_stop)/2.0
        v_func = self.nomo_block.grid_box.v_func
        u_func = self.nomo_block.grid_box.u_func
        u_value = u_func(u)  # = y
        func_opt = lambda x: (v_func(x, v) - u_value) ** 2  # func to minimize
        # let's try to find good starting point for optimization
        x_range = arange(x_start, x_stop, (x_stop - x_start) / 30.0, dtype=complex)
        #        print "x_range:"
        #        print x_range
        # use complex numbers to filter results with complex part
        #values = func_opt(x_range.astype(complex))
        values = x_range
        values_list_complex = values.tolist()
        values_list = []
        for value in values_list_complex:
            if value.imag == 0:
                values_list.append(value.real)
            else:
                values_list.append(1e12)  # large number
            #        print "values_list:"
            #        print values_list
        min_x_idx = values_list.index(min(values_list))
        x_init = x_range[min_x_idx]
        #        print "x_start %g"%x_start
        #        print "x_stop %g"%x_stop
        #        print "x_init %g"%x_init
        # find x point where u meets v = optimization
        x_opt = fmin(func_opt, [x_init], disp=0, maxiter=1e5, maxfun=1e5, ftol=1e-8, xtol=1e-8)[0]
        x_transformed = self.nomo_block._give_trafo_x_(x_opt, u_value)
        y_transformed = self.nomo_block._give_trafo_y_(x_opt, u_value)
        return x_transformed, y_transformed, x_opt, u_value 
开发者ID:lefakkomies,项目名称:pynomo,代码行数:41,代码来源:isopleth.py

示例13: find_log_ticks

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import arange [as 别名]
def find_log_ticks(start, stop):
    """
    finds tick values for linear axis
    """
    if (start < stop):
        min, max = start, stop
    else:
        min, max = stop, start
    # lists for ticks
    tick_0_list = []
    tick_1_list = []
    tick_2_list = []
    max_decade = math.ceil(math.log10(max))
    min_decade = math.floor(math.log10(min))
    start_ax = None
    stop_ax = None
    for decade in scipy.arange(min_decade, max_decade + 1, 1):
        # for number in scipy.concatenate((scipy.arange(1,2,0.2),scipy.arange(2,3,0.5),scipy.arange(3,10,1))):
        for number in [1, 1.2, 1.4, 1.6, 1.8, 2.0, 2.5, 3, 4, 5, 6, 7, 8, 9]:
            u = number * 10.0 ** decade
            if u >= min and u <= max:
                if start_ax == None:
                    start_ax = number
                stop_ax = number
                if number == 1:
                    tick_0_list.append(u)
                if number in [2, 3, 4, 5, 6, 7, 8, 9]:
                    tick_1_list.append(u)
                if number in [1.2, 1.4, 1.6, 1.8, 2.5]:
                    tick_2_list.append(u)
    # print tick_0_list
    # print tick_1_list
    # print tick_2_list
    return tick_0_list, tick_1_list, tick_2_list, start_ax, stop_ax 
开发者ID:lefakkomies,项目名称:pynomo,代码行数:36,代码来源:nomo_axis.py

示例14: MikotaPair

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import arange [as 别名]
def MikotaPair(n):
    # Mikota pair acts as a nice test since the eigenvalues
    # are the squares of the integers n, n=1,2,...
    x = arange(1,n+1)
    B = diag(1./x)
    y = arange(n-1,0,-1)
    z = arange(2*n-1,0,-2)
    A = diag(z)-diag(y,-1)-diag(y,1)
    return A,B 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:11,代码来源:test_lobpcg.py

示例15: calculo

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import arange [as 别名]
def calculo(self):
        ind1=self.Comp1.currentIndex()
        ind2=self.Comp2.currentIndex()
        if ind1!=ind2:
            zi=arange(0.025, 1., 0.025)
            id1=self.indices[ind1]
            id2=self.indices[ind2]
            x=[0]
            y=[0]
            for z in zi:
                try:
                    fraccion=[0.]*len(self.indices)
                    fraccion[ind1]=z
                    fraccion[ind2]=1-z
                    mez=Mezcla(tipo=3, fraccionMolar=fraccion, caudalMasico=1.)
                    tb=mez.componente[0].Tb
                    corr=Corriente(T=tb, P=101325., mezcla=mez)
                    T=corr.eos._Dew_T()
                    corr=Corriente(T=T, P=101325., mezcla=mez)
                    while corr.Liquido.fraccion[0]==corr.Gas.fraccion[0] and corr.T<corr.mezcla.componente[1].Tb:
                        corr=Corriente(T=corr.T-0.1, P=101325., mezcla=mez)
                    x.append(corr.Liquido.fraccion[0])
                    y.append(corr.Gas.fraccion[0])
                except:
                    pass
            x.append(1)
            y.append(1)
            self.rellenar(x, y) 
开发者ID:jjgomera,项目名称:pychemqt,代码行数:30,代码来源:plots.py


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