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


Python scipy.zeros方法代码示例

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


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

示例1: impz

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import zeros [as 别名]
def impz(b,a):
    """Pseudo implementation of the impz method of MATLAB"""
#% Compute time vector
# M = 0;  NN = [];
# if isempty(N)
#   % if not specified, determine the length
#   if isTF
#     N = impzlength(b,a,.00005);
#   else
#     N  = impzlength(b,.00005);
#   end
    p = np.roots(a)
    N = stableNmarginal_length(p, 0.00005, 0)
    N = len(b) * len(b) * len(b) # MATLAB AUTOFINDS THE SIZE HERE... 
    #TODO: Implement some way of finding the autosieze of this... I used a couple of examples... matlab gave 43 as length we give 64
    x = zeros(N)
    x[0] = 1
    h = lfilter(b,a, x)
    return h 
开发者ID:awesomebytes,项目名称:parametric_modeling,代码行数:21,代码来源:impz.py

示例2: delta_calc

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import zeros [as 别名]
def delta_calc(airtemp):
    """
    Calculates slope of saturation vapour pressure curve at air temperature [kPa/Celsius]
    http://www.fao.org/docrep/x0490e/x0490e07.htm
    :param airtemp: Temperature in Celsius
    :return: slope of saturation vapour pressure curve [kPa/Celsius]
    """
    l = sp.size(airtemp)
    if l < 2:
        temp = airtemp + 237.3
        b = 0.6108*(math.exp((17.27*airtemp)/temp))
        delta = (4098*b)/(temp**2)
    else:
        delta = sp.zeros(l)
        for i in range(0, l):
            temp = airtemp[i] + 237.3
            b = 0.6108*(math.exp(17.27*airtemp[i])/temp)
            delta[i] = (4098*b)/(temp**2)
    return delta 
开发者ID:Kirubaharan,项目名称:hydrology,代码行数:21,代码来源:ch_616_daily_wb.py

示例3: delta_calc

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import zeros [as 别名]
def delta_calc(airtemp):
    """
    Calculates slope of saturation vapour pressure curve at air temperature [kPa/Celsius]
    http://www.fao.org/docrep/x0490e/x0490e07.htm
    :param airtemp: Temperature in Celsius
    :return: slope of saturation vapour pressure curve [kPa/Celsius]
    """
    l = sp.size(airtemp)
    if l < 2:
        temp_kelvin = airtemp + 237.3
        b = 0.6108*(math.exp((17.27*airtemp)/temp_kelvin))
        delta = (4098*b)/(temp_kelvin**2)
    else:
        delta = sp.zeros(l)
        for i in range(0, l):
            temp_kelvin = airtemp[i] + 237.3
            b = 0.6108*(math.exp(17.27*airtemp[i])/temp_kelvin)
            delta[i] = (4098*b)/(temp_kelvin**2)
    return delta 
开发者ID:Kirubaharan,项目名称:hydrology,代码行数:21,代码来源:ch_591_30_min_wb.py

示例4: delta_calc

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import zeros [as 别名]
def delta_calc(airtemp):
    """
    Calculates slope of saturation vapour pressure curve at air temperature [kPa/Celsius]
    http://www.fao.org/docrep/x0490e/x0490e07.htm

    :param airtemp: Temperature in Celsius
    :return: slope of saturation vapour pressure curve [kPa/Celsius]
    """
    l = sp.size(airtemp)
    if l < 2:
        temp = airtemp + 237.3
        b = 0.6108 * (math.exp((17.27 * airtemp) / temp))
        delta = (4098 * b) / (temp ** 2)
    else:
        delta = sp.zeros(l)
        for i in range(0, l):
            temp = airtemp[i] + 237.3
            b = 0.6108 * (math.exp(17.27 * airtemp[i]) / temp)
            delta[i] = (4098 * b) / (temp ** 2)
    return delta 
开发者ID:Kirubaharan,项目名称:hydrology,代码行数:22,代码来源:checkdam.py

示例5: calculate_daily_extraterrestrial_irradiation

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import zeros [as 别名]
def calculate_daily_extraterrestrial_irradiation(doy, latitude):
    lat = latitude
    l = np.size(doy)
    s = 0.0820  # MJ m-2 min-1
    lat_rad = lat * (math.pi / 180)
    if l < 2:
        day = doy
        dr = 1 + (0.033 * math.cos((2 * math.pi * day) / 365))  # inverse relative distance Earth-Sun
        dt = 0.409 * math.sin(((2 * math.pi * day) / 365) - 1.39)  # solar declination in radian
        ws = math.acos(-math.tan(lat_rad) * math.tan(dt))   # sunset hour angle in radian
        rext = ((24* 60) / math.pi) * s * dr * ((ws * math.sin(lat_rad) * math.sin(dt)) + (math.cos(lat_rad) * math.cos(dt) * math.sin(ws)))  # MJm-2day-1
    else:
        rext = np.zeros(l)
        for i in range(0, l):
            day = doy[i]
            dr = 1 + (0.033 * math.cos((2 * math.pi * day) / 365))  # inverse relative distance Earth-Sun
            dt = 0.409 * math.sin(((2 * math.pi * day) / 365) - 1.39)  # solar declination in radian
            ws = math.acos(-math.tan(lat_rad) * math.tan(dt))  # sunset hour angle in radian
            rext[i] = ((24 * 60) / math.pi) * s * dr * ((ws * math.sin(lat_rad) * math.sin(dt)) + (math.cos(lat_rad) * math.cos(dt) * math.sin(ws)))  # MJm-2day-1
    return rext 
开发者ID:Kirubaharan,项目名称:hydrology,代码行数:22,代码来源:checkdam.py

示例6: gap

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import zeros [as 别名]
def gap(data, refs=None, nrefs=20, ks=range(1,11), method=None):
    shape = data.shape
    if refs is None:
        tops = data.max(axis=0)
        bots = data.min(axis=0)
        dists = scipy.matrix(scipy.diag(tops-bots))

        rands = scipy.random.random_sample(size=(shape[0], shape[1], nrefs))
        for i in range(nrefs):
            rands[:, :, i] = rands[:, :, i]*dists+bots
    else:
        rands = refs
    gaps = scipy.zeros((len(ks),))
    for (i, k) in enumerate(ks):
        g1 = method(n_clusters=k).fit(data)
        (kmc, kml) = (g1.cluster_centers_, g1.labels_)
        disp = sum([euclidean(data[m, :], kmc[kml[m], :]) for m in range(shape[0])])

        refdisps = scipy.zeros((rands.shape[2],))
        for j in range(rands.shape[2]):
            g2 = method(n_clusters=k).fit(rands[:, :, j])
            (kmc, kml) = (g2.cluster_centers_, g2.labels_)
            refdisps[j] = sum([euclidean(rands[m, :, j], kmc[kml[m],:]) for m in range(shape[0])])
        gaps[i] = scipy.log(scipy.mean(refdisps))-scipy.log(disp)
    return gaps 
开发者ID:szairis,项目名称:sakmapper,代码行数:27,代码来源:network.py

示例7: coupling_optim_garrick

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import zeros [as 别名]
def coupling_optim_garrick(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 
	
	for k in xrange(n_bin):
		kyn = (kernel*f_garrick[:,:,k])*y[:,s.newaxis]*y[s.newaxis,:]
		creation[k] = s.sum(kyn)
	creation=0.5*creation
	out=creation+destruction
	return out



#Now I work with the function for espressing smoluchowski equation when a uniform grid is used 
开发者ID:ActiveState,项目名称:code,代码行数:19,代码来源:recipe-576547.py

示例8: coupling_optim

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import zeros [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

示例9: star_graph_lumped

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import zeros [as 别名]
def star_graph_lumped(N, tau, gamma, I0, tmin, tmax, tcount):
    times = scipy.linspace(tmin, tmax, tcount)
    #    [[central node infected] + [central node susceptible]]
    #X = [Y_1^1, Y_1^2, ..., Y_1^{N}, Y_2^0, Y_2^1, ..., Y_2^{N-1}]
    X0 = scipy.zeros(2*N)  #length 2*N of just 0 entries
    X0[I0]=I0*1./N #central infected, + I0-1 periph infected prob
    X0[N+I0] = 1-I0*1./N #central suscept + I0 periph infected
    X = EoN.my_odeint(star_graph_dX, X0, times, args = (tau, gamma, N))
    #X looks like [[central susceptible,k periph] [ central inf, k-1 periph]] x T

    central_inf = X[:,:N]
    central_susc = X[:,N:]

    I = scipy.array([ sum(k*central_susc[t][k] for k in range(N))
            + sum((k+1)*central_inf[t][k] for k in range(N))
            for t in range(len(X))])
    S = N-I
    return times, S, I 
开发者ID:springer-math,项目名称:Mathematics-of-Epidemics-on-Networks,代码行数:20,代码来源:fig2p11.py

示例10: star_graph_lumped

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import zeros [as 别名]
def star_graph_lumped(N, tau, gamma, I0, tmin, tmax, tcount):
    times = scipy.linspace(tmin, tmax, tcount)
    #    [[central node infected] + [central node susceptible]]
    #X = [Y_1^1, Y_1^2, ..., Y_1^{N}, Y_2^0, Y_2^1, ..., Y_2^{N-1}]
    X0 = scipy.zeros(2*N)  #length 2*N of just 0 entries
    #X0[I0]=I0*1./N #central infected, + I0-1 periph infected prob
    X0[N+I0] = 1#-I0*1./N #central suscept + I0 periph infected
    X = EoN.my_odeint(star_graph_dX, X0, times, args = (tau, gamma, N))
    #X looks like [[central susceptible,k periph] [ central inf, k-1 periph]] x T

    central_susc = X[:,N:]
    central_inf = X[:,:N]
    print(central_susc[-1][:])
    print(central_inf[-1][:])
    I = scipy.array([ sum(k*central_susc[t][k] for k in range(N))
              + sum((k+1)*central_inf[t][k] for k in range(N))
              for t in range(len(X))])
    S = N-I
    return times, S, I 
开发者ID:springer-math,项目名称:Mathematics-of-Epidemics-on-Networks,代码行数:21,代码来源:fig3p2.py

示例11: _flat_field

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import zeros [as 别名]
def _flat_field(X, uniformity_thresh):
    """."""

    Xhoriz = _low_frequency_horiz(X, sigma=4.0)
    Xhorizp = _low_frequency_horiz(X, sigma=3.0)
    nl, nb, nc = X.shape
    FF = s.zeros((nb, nc))
    use_ff = s.ones((X.shape[0], X.shape[2])) > 0
    for b in range(nb):
        xsub = Xhoriz[:, b, :]
        xsubp = Xhorizp[:, b, :]
        mu = xsub.mean(axis=0)
        dists = abs(xsub - mu)
        distsp = abs(xsubp - mu)
        thresh = _percentile(dists.flatten(), 90.0)
        uthresh = dists * uniformity_thresh
        #use       = s.logical_and(dists<thresh, abs(dists-distsp) < uthresh)
        use = dists < thresh
        FF[b, :] = ((xsub*use).sum(axis=0)/use.sum(axis=0)) / \
            ((X[:, b, :]*use).sum(axis=0)/use.sum(axis=0))
        use_ff = s.logical_and(use_ff, use)
    return FF, Xhoriz, Xhorizp, s.array(use_ff) 
开发者ID:isofit,项目名称:isofit,代码行数:24,代码来源:instrument_model.py

示例12: __MR_W_D_matrix

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import zeros [as 别名]
def __MR_W_D_matrix(self,img,labels):
        s = sp.amax(labels)+1
        vect = self.__MR_superpixel_mean_vector(img,labels)
        
        adj = self.__MR_get_adj_loop(labels)
        
        W = sp.spatial.distance.squareform(sp.spatial.distance.pdist(vect))
        
        W = sp.exp(-1*W / self.weight_parameters['delta'])
        W[adj.astype(np.bool)] = 0
        

        D = sp.zeros((s,s)).astype(float)
        for i in range(s):
            D[i, i] = sp.sum(W[i])

        return W,D 
开发者ID:ruanxiang,项目名称:mr_saliency,代码行数:19,代码来源:MR.py

示例13: compute_score

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import zeros [as 别名]
def compute_score(self, img_idx, y, x, mask):
    " Compute the score for deck or met with idx "
    qtrwin = self.winsize/2
    if mask==0:
      mask_file = self.datafiles[img_idx].split('.')[0] + '.jpg'
    elif mask==1:
      mask_file = self.datafiles[img_idx].split('.')[0] + '.msk.jpg'
    else:
      mask_file = self.datafiles[img_idx].split('.')[0] + '.shadow.jpg'
      
    selections_pad = N.zeros((self.height[img_idx] + self.winsize, 
                              self.width[img_idx] + self.winsize))
    mask_img  = cv2.imread(mask_file, 0)
    selections_pad[qtrwin:self.height[img_idx]+qtrwin,
                   qtrwin:self.width[img_idx]+qtrwin] = mask_img
    csel_mask = selections_pad[y:y+self.winsize, x:x+self.winsize]
    
    # Matches are pixels with intensity 255, so divide by this
    # to get number of matching pixels.
    return (csel_mask.sum()/255) 
开发者ID:wkiri,项目名称:DEMUD,代码行数:22,代码来源:dataset_navcam.py

示例14: test_lyap

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import zeros [as 别名]
def test_lyap(self):
        A = array([[-1, 1],[-1, 0]])
        Q = array([[1,0],[0,1]])
        X = lyap(A,Q)
        # print("The solution obtained is ", X)
        assert_array_almost_equal(A.dot(X) + X.dot(A.T) + Q, zeros((2,2)))

        A = array([[1, 2],[-3, -4]])
        Q = array([[3, 1],[1, 1]])
        X = lyap(A,Q)
        # print("The solution obtained is ", X)
        assert_array_almost_equal(A.dot(X) + X.dot(A.T) + Q, zeros((2,2))) 
开发者ID:python-control,项目名称:python-control,代码行数:14,代码来源:mateqn_test.py

示例15: test_lyap_sylvester

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import zeros [as 别名]
def test_lyap_sylvester(self):
        A = 5
        B = array([[4, 3], [4, 3]])
        C = array([2, 1])
        X = lyap(A,B,C)
        # print("The solution obtained is ", X)
        assert_array_almost_equal(A * X + X.dot(B) + C, zeros((1,2)))

        A = array([[2,1],[1,2]])
        B = array([[1,2],[0.5,0.1]])
        C = array([[1,0],[0,1]])
        X = lyap(A,B,C)
        # print("The solution obtained is ", X)
        assert_array_almost_equal(A.dot(X) + X.dot(B) + C, zeros((2,2))) 
开发者ID:python-control,项目名称:python-control,代码行数:16,代码来源:mateqn_test.py


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