當前位置: 首頁>>代碼示例>>Python>>正文


Python numpy.correlate方法代碼示例

本文整理匯總了Python中numpy.correlate方法的典型用法代碼示例。如果您正苦於以下問題:Python numpy.correlate方法的具體用法?Python numpy.correlate怎麽用?Python numpy.correlate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在numpy的用法示例。


在下文中一共展示了numpy.correlate方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _autocorr

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import correlate [as 別名]
def _autocorr(data):
    """
    Calculates the auto correlation of a given array.

    Parameters
    ----------
    data : array-like
        The array to calculate the autocorrelation of

    Returns
    -------
    u : ndarray
        The array of autocorrelations
    """
    u = np.correlate(data, data, mode='full')
    # Take upper half of correlation matrix
    return u[u.size // 2:] 
開發者ID:ME-ICA,項目名稱:tedana,代碼行數:19,代碼來源:ma_pca.py

示例2: _presample_varcov

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import correlate [as 別名]
def _presample_varcov(self, params):
        """
        Returns the inverse of the presample variance-covariance.

        Notes
        -----
        See Hamilton p. 125
        """
        k = self.k_trend
        p = self.k_ar
        p1 = p+1

        # get inv(Vp) Hamilton 5.3.7
        params0 = np.r_[-1, params[k:]]

        Vpinv = np.zeros((p, p), dtype=params.dtype)
        for i in range(1, p1):
            Vpinv[i-1, i-1:] = np.correlate(params0, params0[:i],)[:-1]
            Vpinv[i-1, i-1:] -= np.correlate(params0[-i:], params0,)[:-1]

        Vpinv = Vpinv + Vpinv.T - np.diag(Vpinv.diagonal())
        return Vpinv 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:24,代碼來源:ar_model.py

示例3: ar_generator

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import correlate [as 別名]
def ar_generator(N=512, sigma=1.):
    # this generates a signal u(n) = a1*u(n-1) + a2*u(n-2) + ... + v(n)
    # where v(n) is a stationary stochastic process with zero mean
    # and variance = sigma
    # this sequence is shown to be estimated well by an order 8 AR system
    taps = np.array([2.7607, -3.8106, 2.6535, -0.9238])
    v = np.random.normal(size=N, scale=sigma**0.5)
    u = np.zeros(N)
    P = len(taps)
    for l in range(P):
        u[l] = v[l] + np.dot(u[:l][::-1], taps[:l])
    for l in range(P,N):
        u[l] = v[l] + np.dot(u[l-P:l][::-1], taps)
    return u, v, taps

#JP: small differences to using np.correlate, because assumes mean(s)=0
#    denominator is N, not N-k, biased estimator
#    misnomer: (biased) autocovariance not autocorrelation
#from nitime.utils 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:21,代碼來源:example_arma.py

示例4: extractMseq

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import correlate [as 別名]
def extractMseq(cover, stego, secret_length, m, tau=1):
	u"""Extract secret informations by spread spectrum using m-sequence.
	@param  cover         : cover data (2 dimensional np.ndarray)
	@param  stego         : stego data (2 dimension np.ndarray)
	@param  secret_length : length of secret information
	@param  m             : M-Sequence
	@param  tau           : embed shift interval
	@return secret        : extracted secret information
	"""

	cover = _image2vrctor(cover)
	stego = _image2vrctor(stego)

	m_length = len(m)

	data = stego - cover
	data = data[:m_length:tau]

	secret_data = correlate(m, data, cycle=CYCLE)
	center = ((m_length-1)*2+1)//2
	secret_data = secret_data[center:center+secret_length]
	secret_data = list(map(_checkData, secret_data))

	return secret_data 
開發者ID:piraaa,項目名稱:VideoDigitalWatermarking,代碼行數:26,代碼來源:watermarking.py

示例5: test_rank0

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import correlate [as 別名]
def test_rank0(self, dt):
        a = np.array(np.random.randn()).astype(dt)
        a += 1j * np.array(np.random.randn()).astype(dt)
        b = np.array(np.random.randn()).astype(dt)
        b += 1j * np.array(np.random.randn()).astype(dt)

        y_r = (correlate(a.real, b.real)
               + correlate(a.imag, b.imag)).astype(dt)
        y_r += 1j * (-correlate(a.real, b.imag) + correlate(a.imag, b.real))

        y = correlate(a, b, 'full')
        assert_array_almost_equal(y, y_r, decimal=self.decimal(dt) - 1)
        assert_equal(y.dtype, dt)

        assert_equal(correlate([1], [2j]), correlate(1, 2j))
        assert_equal(correlate([2j], [3j]), correlate(2j, 3j))
        assert_equal(correlate([3j], [4]), correlate(3j, 4)) 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:19,代碼來源:test_signaltools.py

示例6: test_consistency_correlate_funcs

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import correlate [as 別名]
def test_consistency_correlate_funcs(self):
        # Compare np.correlate, signal.correlate, signal.correlate2d
        a = np.arange(5)
        b = np.array([3.2, 1.4, 3])
        for mode in ['full', 'valid', 'same']:
            assert_almost_equal(np.correlate(a, b, mode=mode),
                                signal.correlate(a, b, mode=mode))
            assert_almost_equal(np.squeeze(signal.correlate2d([a], [b],
                                                              mode=mode)),
                                signal.correlate(a, b, mode=mode))

            # See gh-5897
            if mode == 'valid':
                assert_almost_equal(np.correlate(b, a, mode=mode),
                                    signal.correlate(b, a, mode=mode))
                assert_almost_equal(np.squeeze(signal.correlate2d([b], [a],
                                                                  mode=mode)),
                                    signal.correlate(b, a, mode=mode)) 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:20,代碼來源:test_signaltools.py

示例7: test_float

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import correlate [as 別名]
def test_float(self):
        self._setup(float)
        z = np.correlate(self.x, self.y, 'full')
        assert_array_almost_equal(z, self.z1)
        z = np.correlate(self.x, self.y[:-1], 'full')
        assert_array_almost_equal(z, self.z1_4)
        z = np.correlate(self.y, self.x, 'full')
        assert_array_almost_equal(z, self.z2)
        z = np.correlate(self.x[::-1], self.y, 'full')
        assert_array_almost_equal(z, self.z1r)
        z = np.correlate(self.y, self.x[::-1], 'full')
        assert_array_almost_equal(z, self.z2r)
        z = np.correlate(self.xs, self.y, 'full')
        assert_array_almost_equal(z, self.zs) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:16,代碼來源:test_numeric.py

示例8: test_object

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import correlate [as 別名]
def test_object(self):
        self._setup(Decimal)
        z = np.correlate(self.x, self.y, 'full')
        assert_array_almost_equal(z, self.z1)
        z = np.correlate(self.y, self.x, 'full')
        assert_array_almost_equal(z, self.z2) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:8,代碼來源:test_numeric.py

示例9: test_no_overwrite

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import correlate [as 別名]
def test_no_overwrite(self):
        d = np.ones(100)
        k = np.ones(3)
        np.correlate(d, k)
        assert_array_equal(d, np.ones(100))
        assert_array_equal(k, np.ones(3)) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:8,代碼來源:test_numeric.py

示例10: test_complex

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import correlate [as 別名]
def test_complex(self):
        x = np.array([1, 2, 3, 4+1j], dtype=complex)
        y = np.array([-1, -2j, 3+1j], dtype=complex)
        r_z = np.array([3-1j, 6, 8+1j, 11+5j, -5+8j, -4-1j], dtype=complex)
        r_z = r_z[::-1].conjugate()
        z = np.correlate(y, x, mode='full')
        assert_array_almost_equal(z, r_z) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:9,代碼來源:test_numeric.py

示例11: xcorr

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import correlate [as 別名]
def xcorr(x, y, maxlags=None):
    """Cross-correlation between two 1D signals of the same length."""
    ns = len(x)
    if len(y) != ns:
        raise ValueError("x and y should have the same length.")
    maxlags = maxlags or ns - 1
    return np.correlate(x, y, mode='full')[ns - 1 - maxlags:ns + maxlags] 
開發者ID:int-brain-lab,項目名稱:ibllib,代碼行數:9,代碼來源:xcorr_numpy.py

示例12: test_float

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import correlate [as 別名]
def test_float(self):
        self._setup(np.float)
        z = np.correlate(self.x, self.y, 'full')
        assert_array_almost_equal(z, self.z1)
        z = np.correlate(self.x, self.y[:-1], 'full')
        assert_array_almost_equal(z, self.z1_4)
        z = np.correlate(self.y, self.x, 'full')
        assert_array_almost_equal(z, self.z2)
        z = np.correlate(self.x[::-1], self.y, 'full')
        assert_array_almost_equal(z, self.z1r)
        z = np.correlate(self.y, self.x[::-1], 'full')
        assert_array_almost_equal(z, self.z2r)
        z = np.correlate(self.xs, self.y, 'full')
        assert_array_almost_equal(z, self.zs) 
開發者ID:abhisuri97,項目名稱:auto-alt-text-lambda-api,代碼行數:16,代碼來源:test_numeric.py

示例13: test_complex

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import correlate [as 別名]
def test_complex(self):
        x = np.array([1, 2, 3, 4+1j], dtype=np.complex)
        y = np.array([-1, -2j, 3+1j], dtype=np.complex)
        r_z = np.array([3-1j, 6, 8+1j, 11+5j, -5+8j, -4-1j], dtype=np.complex)
        r_z = r_z[::-1].conjugate()
        z = np.correlate(y, x, mode='full')
        assert_array_almost_equal(z, r_z) 
開發者ID:abhisuri97,項目名稱:auto-alt-text-lambda-api,代碼行數:9,代碼來源:test_numeric.py

示例14: ccf

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import correlate [as 別名]
def ccf(x, y, unbiased=True):
    '''cross-correlation function for 1d

    Parameters
    ----------
    x, y : arrays
       time series data
    unbiased : boolean
       if True, then denominators for autocovariance is n-k, otherwise n

    Returns
    -------
    ccf : array
        cross-correlation function of x and y

    Notes
    -----
    This is based np.correlate which does full convolution. For very long time
    series it is recommended to use fft convolution instead.

    If unbiased is true, the denominator for the autocovariance is adjusted
    but the autocorrelation is not an unbiased estimtor.

    '''
    cvf = ccovf(x, y, unbiased=unbiased, demean=True)
    return cvf / (np.std(x) * np.std(y)) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:28,代碼來源:stattools.py

示例15: norm_corr

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import correlate [as 別名]
def norm_corr(x,y,mode = 'valid'):
    """Returns the correlation between two ndarrays, by calling np.correlate in
'same' mode and normalizing the result by the std of the arrays and by
their lengths. This results in a correlation = 1 for an auto-correlation"""

    return ( np.correlate(x,y,mode) /
             (np.std(x)*np.std(y)*(x.shape[-1])) )



# from matplotlib axes.py
# note: self is axis 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:14,代碼來源:example_arma.py


注:本文中的numpy.correlate方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。