Python scipy 模块,real() 实例源码

我们从Python开源项目中,提取了以下10个代码示例,用于说明如何使用scipy.real()

项目:Mendelssohn    作者:diggerdu    | 项目源码 | 文件源码
def istft(X, scale = 1, overlap=4):   
    fftsize=(X.shape[1]-1)*2
    hop = fftsize / overlap
    w = scipy.hanning(fftsize+1)[:-1]
    x = scipy.zeros(X.shape[0]*hop)
    wsum = scipy.zeros(X.shape[0]*hop) 
    for n,i in enumerate(range(0, len(x)-fftsize, hop)): 
        x[i:i+fftsize] += scipy.real(np.fft.irfft(X[n])) * w   # overlap-add
        wsum[i:i+fftsize] += w ** 2.
    pos = wsum != 0
    x[pos] /= wsum[pos]
    x = x * scale
    return x.astype(np.int16)
项目:pyabc    作者:neuralyzer    | 项目源码 | 文件源码
def fit(self, X, w):
        if len(X) == 0:
            raise NotEnoughParticles("Fitting not possible.")
        self.X_arr = X.as_matrix()

        ctree = cKDTree(X)
        _, indices = ctree.query(X, k=min(self.k + 1, X.shape[0]))

        covs, inv_covs, dets = list(zip(*[self._cov_and_inv(n, indices)
                                    for n in range(X.shape[0])]))
        self.covs = sp.array(covs)
        self.inv_covs = sp.array(inv_covs)
        self.determinants = sp.array(dets)

        self.normalization = sp.sqrt(
            (2 * sp.pi) ** self.X_arr.shape[1] * self.determinants)

        if not sp.isreal(self.normalization).all():
            raise Exception("Normalization not real")
        self.normalization = sp.real(self.normalization)
项目:MachineLearning    作者:timomernick    | 项目源码 | 文件源码
def create_spectrogram(wav):
    spec = stft.stft(wav, fftsize=fft_size)

    num_samples = spec.shape[0]

    # zero DC component
    #spec[0:num_samples,0:1] = 0.0

    # zero part where voice never is
    #spec[0:num_samples,0:10] = 0.0

    spec *= spec_norm

    spec_mags = np.sqrt(np.square(scipy.real(spec)) + np.square(scipy.imag(spec)))

    return spec, spec_mags
项目:orthopy    作者:nschloe    | 项目源码 | 文件源码
def _gauss_from_coefficients_numpy(alpha, beta):
    assert isinstance(alpha, numpy.ndarray)
    assert isinstance(beta, numpy.ndarray)

    # eigh_tridiagonal is only available from scipy 1.0.0
    try:
        from scipy.linalg import eigh_tridiagonal
    except ImportError:
        # Use eig_banded
        x, V = eig_banded(numpy.vstack((numpy.sqrt(beta), alpha)), lower=False)
        w = beta[0]*scipy.real(scipy.power(V[0, :], 2))
    else:
        x, V = eigh_tridiagonal(alpha, numpy.sqrt(beta[1:]))
        w = beta[0] * V[0, :]**2

    return x, w
项目:Mendelssohn    作者:diggerdu    | 项目源码 | 文件源码
def istft(X, scale = 1, overlap=4):   
    fftsize=(X.shape[1]-1)*2
    hop = fftsize / overlap
    w = scipy.hanning(fftsize+1)[:-1]
    x = scipy.zeros(X.shape[0]*hop)
    wsum = scipy.zeros(X.shape[0]*hop) 
    for n,i in enumerate(range(0, len(x)-fftsize, hop)): 
        x[i:i+fftsize] += scipy.real(np.fft.irfft(X[n])) * w   # overlap-add
        wsum[i:i+fftsize] += w ** 2.
    pos = wsum != 0
    x[pos] /= wsum[pos]
    x = x * scale
    return x.astype(np.int16)
项目:SpeechSeparation    作者:Unisound    | 项目源码 | 文件源码
def istft(X, fs, T, hop):
    #x = scipy.zeros(T*fs)
    x = scipy.zeros(T)
    framesamp = X.shape[1]
    hopsamp = int(hop*fs)
    for n,i in enumerate(range(0, len(x)-framesamp, hopsamp)):
        x[i:i+framesamp] += scipy.real(scipy.fftpack.ifft(X[n]))
    return x
项目:SpeechSeparation    作者:Unisound    | 项目源码 | 文件源码
def irstft(X, fs, T, hop):
    #x = scipy.zeros(T*fs)
    x = scipy.zeros(T)
    framesamp = X.shape[1]
    hopsamp = int(hop*fs)
    for n,i in enumerate(range(0, len(x)-framesamp, hopsamp)):
        x[i:i+framesamp] += scipy.real(scipy.fftpack.irfft(X[n]))
    return x
# an audio-making function
项目:MachineLearning    作者:timomernick    | 项目源码 | 文件源码
def create_spectrogram(wav):
    spec = stft.stft(wav, fftsize=fft_size)

    num_samples = spec.shape[0]

    # zero DC component
    #spec[0:num_samples,0:1] = 0.0

    spec *= spec_norm

    spec_mags = np.sqrt(np.square(scipy.real(spec)) + np.square(scipy.imag(spec)))

    return spec, spec_mags
项目:MachineLearning    作者:timomernick    | 项目源码 | 文件源码
def istft(X, overlap=4):   
    fftsize=(X.shape[1]-1)*2
    hop = fftsize / overlap
    w = scipy.hanning(fftsize+1)[:-1]
    x = scipy.zeros(X.shape[0]*hop)
    wsum = scipy.zeros(X.shape[0]*hop) 
    for n,i in enumerate(range(0, len(x)-fftsize, hop)): 
        x[i:i+fftsize] += scipy.real(np.fft.irfft(X[n])) * w   # overlap-add
        wsum[i:i+fftsize] += w ** 2.
    pos = wsum != 0
    x[pos] /= wsum[pos]
    return x
项目:bird-species-classification    作者:johnmartinsson    | 项目源码 | 文件源码
def istft(X, fs, T, hop):
    x = scipy.zeros(T*fs)
    framesamp = X.shape[1]
    hopsamp = int(hop*fs)
    for n,i in enumerate(range(0, len(x)-framesamp, hopsamp)):
        x[i:i+framesamp] += scipy.real(scipy.ifft(X[n]))
    return x