當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。