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


Python scipy.array方法代码示例

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


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

示例1: _break_points

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import array [as 别名]
def _break_points(num, den):
    """Extract break points over real axis and gains given these locations"""
    # type: (np.poly1d, np.poly1d) -> (np.array, np.array)
    dnum = num.deriv(m=1)
    dden = den.deriv(m=1)
    polynom = den * dnum - num * dden
    real_break_pts = polynom.r
    # don't care about infinite break points
    real_break_pts = real_break_pts[num(real_break_pts) != 0]
    k_break = -den(real_break_pts) / num(real_break_pts)
    idx = k_break >= 0   # only positives gains
    k_break = k_break[idx]
    real_break_pts = real_break_pts[idx]
    if len(k_break) == 0:
        k_break = [0]
        real_break_pts = den.roots
    return k_break, real_break_pts 
开发者ID:python-control,项目名称:python-control,代码行数:19,代码来源:rlocus.py

示例2: readWav

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import array [as 别名]
def readWav():
    """
        Reads a sound wave from a standard input and finds its parameters.
    """

    # Read the sound wave from the input.
    sound_wave = wave.open(sys.argv[1], "r")

    # Get parameters of the sound wave.
    nframes = sound_wave.getnframes()
    framerate = sound_wave.getframerate()
    params = sound_wave.getparams()
    duration = nframes / float(framerate)

    print "frame rate: %d " % (framerate,)
    print "nframes: %d" % (nframes,)
    print "duration: %f seconds" % (duration,)
    print scipy.array(sound_wave)

    return (sound_wave, nframes, framerate, duration, params) 
开发者ID:Agerrr,项目名称:Automated_Music_Transcription,代码行数:22,代码来源:first_peaks_method.py

示例3: readWav

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import array [as 别名]
def readWav():
    """
        Reads a sound wave from a standard input and finds its parameters.
    """

    # Read the sound wave from the input.
    sound_wave = wave.open(sys.argv[1], "r")
  
    # Get parameters of the sound wave.
    nframes = sound_wave.getnframes()
    framerate = sound_wave.getframerate()
    params = sound_wave.getparams()
    duration = nframes / float(framerate)

    print "frame rate: %d " % (framerate,)
    print "nframes: %d" % (nframes,)
    print "duration: %f seconds" % (duration,)
    print scipy.array(sound_wave)

    return (sound_wave, nframes, framerate, duration, params) 
开发者ID:Agerrr,项目名称:Automated_Music_Transcription,代码行数:22,代码来源:least_squares_first_peaks_2.py

示例4: test_fetch_one_column

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

示例5: find_range

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import array [as 别名]
def find_range(array, x):
    """
    Function to calculate bounding intervals from array to do piecewise linear interpolation.

    :param array: list of values
    :param x: interpolation value
    :return: boundary interval

    Examples:
        >>> array = [0, 1, 2, 3, 4]
        >>>find_range(array, 1.5)
        1, 2
    """
    if x < max(array):
        start = bisect_left(array, x)
        return array[start-1], array[start]
    else:
        return min(array), max(array) 
开发者ID:Kirubaharan,项目名称:hydrology,代码行数:20,代码来源:checkdam.py

示例6: Regresion

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import array [as 别名]
def Regresion(self):
        t=array(self.KEq_Tab.getColumn(0)[:-1])
        k=array(self.KEq_Tab.getColumn(1)[:-1])
        if len(t)>=4:
            if 4<=len(t)<8:
                inicio=r_[0, 0, 0, 0]
                f=lambda par, T: exp(par[0]+par[1]/T+par[2]*log(T)+par[3]*T)
                resto=lambda par, T, k: k-f(par, T)
            else:
                inicio=r_[0, 0, 0, 0, 0, 0, 0, 0]
                f=lambda par, T: exp(par[0]+par[1]/T+par[2]*log(T)+par[3]*T+par[4]*T**2+par[5]*T**3+par[6]*T**4+par[7]*T**5)
                resto=lambda par, T, k: k-f(par, T)

            ajuste=leastsq(resto,inicio,args=(t, k))
            kcalc=f(ajuste[0], t)
            error=(k-kcalc)/k*100
            self.KEq_Dat.setColumn(0, ajuste[0])
            self.KEq_Tab.setColumn(2, kcalc)
            self.KEq_Tab.setColumn(3, error)

            if ajuste[1] in [1, 2, 3, 4]:
                self.ajuste=ajuste[0] 
开发者ID:jjgomera,项目名称:pychemqt,代码行数:24,代码来源:UI_reactor.py

示例7: fill

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import array [as 别名]
def fill(self, array):
        """Populate the widgets with the DIPPR coefficient in array in format
        [eq, A, B, C, D, E, Tmin, Tmax]"""
        if array[0] != 0:
            for valor, entrada in zip(array[1:6], self.coeff):
                entrada.setValue(valor)
            self.tmin.setValue(array[6])
            self.tmax.setValue(array[7])
            self.eq.setValue(array[0])
            latex = self.latex[array[0]]
            tex = "$%s = %s$" % (self.proptex, latex)
            self.eqformula.setTex(tex)
            self.eq.setVisible(False)
            self.eqformula.setVisible(True)
            self.btnPlot.setEnabled(True)
            self.equation = array[0] 
开发者ID:jjgomera,项目名称:pychemqt,代码行数:18,代码来源:viewComponents.py

示例8: complete_graph_dX

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import array [as 别名]
def complete_graph_dX(X, t, tau, gamma, N):
    r'''This system is given in Proposition 2.3, taking Q=S, T=I
    f_{SI}(k) = f_{QT}= k*\tau
    f_{IS}(k) = f_{TQ} = \gamma

    \dot{Y}^0 = \gamma Y^1 - 0\\
    \dot{Y}^1 = 2\gamma Y^2  + 0Y^0 - (\gamma + (N-1)\tau)Y^1
    \dot{Y}^2 = 3\gamma Y^3 + (N-1)\tau Y^1 - (2\gamma+2(N-2))Y^2
    ...
    \dot{Y}^N = (N-1)\tau Y^{N-1} - N\gamma Y^N
    Note that X has length N+1
    '''
    #X[k] is probability of k infections.
    dX = []
    dX.append(gamma*X[1])
    for k in range(1,N):
        dX.append((k+1)*gamma*X[k+1]+ (N-k+1)*(k-1)*tau*X[k-1]
                    - ((N-k)*k*tau + k*gamma)*X[k])
    dX.append((N-1)*tau*X[N-1] - N*gamma*X[N])

    return scipy.array(dX) 
开发者ID:springer-math,项目名称:Mathematics-of-Epidemics-on-Networks,代码行数:23,代码来源:fig2p11.py

示例9: star_graph_lumped

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

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import array [as 别名]
def complete_graph_dX(X, t, tau, gamma, N):
    r'''This system is given in Proposition 2.3, taking Q=S, T=I
    f_{SI}(k) = f_{QT}= k*\tau 
    f_{IS}(k) = f_{TQ} = \gamma
    
    \dot{Y}^0 = \gamma Y^1 - 0\\
    \dot{Y}^1 = 2\gamma Y^2  + 0Y^0 - (\gamma + (N-1)\tau)Y^1
    \dot{Y}^2 = 3\gamma Y^3 + (N-1)\tau Y^1 - (2\gamma+2(N-2))Y^2
    ...
    \dot{Y}^N = (N-1)\tau Y^{N-1} - N\gamma Y^N
    Note that X has length N+1
    '''
    #X[k] is probability of k infections.  
    dX = []
    dX.append(gamma*X[1])
    for k in range(1,N):
        dX.append((k+1)*gamma*X[k+1]+ (N-k+1)*(k-1)*tau*X[k-1]
                    - ((N-k)*k*tau + k*gamma)*X[k])
    dX.append((N-1)*tau*X[N-1] - N*gamma*X[N])
    
    return scipy.array(dX) 
开发者ID:springer-math,项目名称:Mathematics-of-Epidemics-on-Networks,代码行数:23,代码来源:fig3p2.py

示例11: star_graph_lumped

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

示例12: get_HRRR_data

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import array [as 别名]
def get_HRRR_data(filename):
    grbs = pygrib.open(filename)

    msgs = [str(grb) for grb in grbs]

    string = 'Geopotential Height:gpm'
    temp = [msg for msg in msgs if msg.find(string) > -1 and msg.find('isobaricInhPa') > -1]
    pressure_levels_Pa = s.array([int(s.split(' ')[3]) for s in temp])

    geo_pot_height_grbs = grbs.select(name = 'Geopotential Height', \
                                      typeOfLevel='isobaricInhPa', level=lambda l: l > 0)
    temperature_grbs = grbs.select(name = 'Temperature', \
                                   typeOfLevel='isobaricInhPa', level=lambda l: l > 0)
    rh_grbs = grbs.select(name = 'Relative humidity', \
                          typeOfLevel='isobaricInhPa', level=lambda l: l > 0)

    lat, lon = geo_pot_height_grbs[0].latlons()

    geo_pot_height = s.stack([grb.values for grb in geo_pot_height_grbs])
    temperature = s.stack([grb.values for grb in temperature_grbs])
    rh = s.stack([grb.values for grb in rh_grbs])

    return lat, lon, geo_pot_height, temperature, rh, pressure_levels_Pa 
开发者ID:isofit,项目名称:isofit,代码行数:25,代码来源:add_HRRR_profiles_to_modtran_config.py

示例13: _flat_field

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

示例14: calc_twostate_weights

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import array [as 别名]
def calc_twostate_weights( data ):
	weights=[0,0,0] # the change cannot have occurred in the last 3 points
	means_mss=calc_mean_mss( data )

	i=0
	try:
		for nA, mean2A, varA, nB, mean2B, varB in means_mss :
			#print "computing for data", nA, mean2A, varA, nB, mean2B, varB
			numf1 = calc_alpha( nA, mean2A, varA )
			numf2 = calc_alpha( nB, mean2B, varB )
			denom = (varA + varB) * (mean2A*mean2B)
			weights.append( (numf1*numf2)/denom) 
			i += 1
	except:
		print "failed at data", i # means_mss[i]
		print "---"
		#print means_mss
		print "---"
		raise

	weights.extend( [0,0] ) # the change cannot have occurred at the last 2 points
	return array( weights ) 
开发者ID:choderalab,项目名称:cpdetect,代码行数:24,代码来源:old2cpDetect.py

示例15: tdft

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import array [as 别名]
def tdft(audio, srate, windowsize, windowshift,fftsize):

    """Calculate the real valued fast Fourier transform of a segment of audio multiplied by a 
    a Hamming window.  Then, convert to decibels by multiplying by 20*log10.  Repeat for all
    segments of the audio."""
    
    windowsamp = int(windowsize*srate)
    shift = int(windowshift*srate)
    window = scipy.hamming(windowsamp)
    spectrogram = scipy.array([20*scipy.log10(abs(np.fft.rfft(window*audio[i:i+windowsamp],fftsize))) 
                     for i in range(0, len(audio)-windowsamp, shift)])
    return spectrogram 
开发者ID:bmoquist,项目名称:Shazam,代码行数:14,代码来源:tdft.py


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