本文整理匯總了Python中scipy.absolute方法的典型用法代碼示例。如果您正苦於以下問題:Python scipy.absolute方法的具體用法?Python scipy.absolute怎麽用?Python scipy.absolute使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類scipy
的用法示例。
在下文中一共展示了scipy.absolute方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: get_stft_bin_freqs
# 需要導入模塊: import scipy [as 別名]
# 或者: from scipy import absolute [as 別名]
def get_stft_bin_freqs(self, stft, framerate):
fft_length = self.HAN_WINDOW * framerate
binResolution = float(framerate) / float(fft_length)
stft_binFrequencies = []
stft_magnitudes = []
for i in range(len(stft)):
binFreqs = []
magnitudes = []
for k in range(len(stft[i])):
binFreq = k * binResolution
if binFreq > self.minFreqConsidered and binFreq < self.maxFreqConsidered:
power_spectrum = scipy.absolute(stft[i][k]) * scipy.absolute(stft[i][k])
if power_spectrum > self.THRESHOLD:
binFreqs.append(binFreq)
magnitudes.append(power_spectrum)
stft_binFrequencies.append(binFreqs)
stft_magnitudes.append(magnitudes)
return (stft_binFrequencies, stft_magnitudes)
示例2: getAlgebraicConnectivity
# 需要導入模塊: import scipy [as 別名]
# 或者: from scipy import absolute [as 別名]
def getAlgebraicConnectivity(self, lanczosVecs = 15, maxiter = 20):
"""
Returns the algebraic connectivity of the higher-order network.
@param lanczosVecs: number of Lanczos vectors to be used in the approximate
calculation of eigenvectors and eigenvalues. This maps to the ncv parameter
of scipy's underlying function eigs.
@param maxiter: scaling factor for the number of iterations to be used in the
approximate calculation of eigenvectors and eigenvalues. The number of iterations
passed to scipy's underlying eigs function will be n*maxiter where n is the
number of rows/columns of the Laplacian matrix.
"""
Log.add('Calculating algebraic connectivity ... ', Severity.INFO)
L = self.getLaplacianMatrix()
# NOTE: ncv sets additional auxiliary eigenvectors that are computed
# NOTE: in order to be more confident to find the one with the largest
# NOTE: magnitude, see https://github.com/scipy/scipy/issues/4987
w = _sla.eigs( L, which="SM", k=2, ncv=lanczosVecs, return_eigenvectors=False, maxiter = maxiter )
evals_sorted = _np.sort(_np.absolute(w))
Log.add('finished.', Severity.INFO)
return _np.abs(evals_sorted[1])
示例3: get_FFT_of_noise
# 需要導入模塊: import scipy [as 別名]
# 或者: from scipy import absolute [as 別名]
def get_FFT_of_noise(self, x, rnorm):
sum_of_singles = x[0] * self.get_FFT(self.first_single) + x[1] * self.get_FFT(self.second_single) + x[2] * self.get_FFT(self.third_single)
fft = scipy.absolute(self.get_FFT(self.chord) - sum_of_singles)
return fft
示例4: get_sum_of_squares
# 需要導入模塊: import scipy [as 別名]
# 或者: from scipy import absolute [as 別名]
def get_sum_of_squares(self, fft):
sum_of_squares = 0.0
for i in range(len(fft)):
sum_of_squares += scipy.absolute(fft[i]) * sscipy.absolute(fft[i])
return sum_of_squares
示例5: plot_power_spectrum
# 需要導入模塊: import scipy [as 別名]
# 或者: from scipy import absolute [as 別名]
def plot_power_spectrum(self, fft):
T = int(600)
pylab.figure('Power spectrum')
pylab.plot(scipy.absolute(fft[:T]) * scipy.absolute(fft[:T]),)
pylab.xlabel('Frequency [Hz]')
pylab.ylabel('Power spectrum []')
pylab.show()
示例6: plotPowerSpectrum
# 需要導入模塊: import scipy [as 別名]
# 或者: from scipy import absolute [as 別名]
def plotPowerSpectrum(FFT, binFrequencies, maxFreq):
"""
Calculates and plots the power spectrum of a given sound wave.
"""
T = int(maxFreq)
pylab.figure('Power spectrum')
pylab.plot(binFrequencies[:T], scipy.absolute(FFT[:T]) * scipy.absolute(FFT[:T]),)
pylab.xlabel('Frequency (Hz)')
pylab.ylabel('Power spectrum (|X[k]|^2)')
pylab.show()
示例7: plotMagnitudeSpectrogram
# 需要導入模塊: import scipy [as 別名]
# 或者: from scipy import absolute [as 別名]
def plotMagnitudeSpectrogram(self, rate, sample, framesz, hop):
"""
Calculates and plots the magnitude spectrum of a given sound wave.
"""
X = self.STFT(sample, rate, framesz, hop)
# Plot the magnitude spectrogram.
pylab.figure('Magnitude spectrogram')
pylab.imshow(scipy.absolute(X.T), origin='lower', aspect='auto',
interpolation='nearest')
pylab.xlabel('Time')
pylab.ylabel('Frequency')
pylab.show()
示例8: getFilteredFFT
# 需要導入模塊: import scipy [as 別名]
# 或者: from scipy import absolute [as 別名]
def getFilteredFFT(self, FFT, duration, threshold):
"""
Returns a list of frequencies with the magnitudes higher than a given threshold.
"""
significantFreqs = []
for i in range(len(FFT)):
power_spectrum = scipy.absolute(FFT[i]) * scipy.absolute(FFT[i])
if power_spectrum > threshold:
significantFreqs.append(i / duration)
return significantFreqs
示例9: calculateFFT
# 需要導入模塊: import scipy [as 別名]
# 或者: from scipy import absolute [as 別名]
def calculateFFT(self, duration, framerate, sample):
"""
Calculates FFT for a given sound wave.
Considers only frequencies with the magnitudes higher than
a given threshold.
"""
fft_length = int(duration * framerate)
fft_length = get_next_power_2(fft_length)
FFT = numpy.fft.fft(sample, n=fft_length)
''' ADJUSTING THRESHOLD '''
threshold = 0
power_spectra = []
for i in range(len(FFT) / 2):
power_spectrum = scipy.absolute(FFT[i]) * scipy.absolute(FFT[i])
if power_spectrum > threshold:
threshold = power_spectrum
power_spectra.append(power_spectrum)
threshold *= 0.1
binResolution = float(framerate) / float(fft_length)
frequency_power = []
# For each bin calculate the corresponding frequency.
for k in range(len(FFT) / 2):
binFreq = k * binResolution
if binFreq > self.minFreqConsidered and binFreq < self.maxFreqConsidered:
power_spectrum = power_spectra[k]
#dB = 10*math.log10(power_spectrum)
if power_spectrum > threshold:
frequency_power.append((binFreq, power_spectrum))
return frequency_power
示例10: getEigenValueGap
# 需要導入模塊: import scipy [as 別名]
# 或者: from scipy import absolute [as 別名]
def getEigenValueGap(self, includeSubPaths=True, lanczosVecs = 15, maxiter = 20):
"""
Returns the eigenvalue gap of the transition matrix.
@param includeSubPaths: whether or not to include subpath statistics in the
calculation of transition probabilities.
"""
#NOTE to myself: most of the time goes for construction of the 2nd order
#NOTE null graph, then for the 2nd order null transition matrix
Log.add('Calculating eigenvalue gap ... ', Severity.INFO)
# Build transition matrices
T = self.getTransitionMatrix(includeSubPaths)
# Compute the two largest eigenvalues
# NOTE: ncv sets additional auxiliary eigenvectors that are computed
# NOTE: in order to be more confident to actually find the one with the largest
# NOTE: magnitude, see https://github.com/scipy/scipy/issues/4987
w2 = _sla.eigs(T, which="LM", k=2, ncv=lanczosVecs, return_eigenvectors=False, maxiter = maxiter)
evals2_sorted = _np.sort(-_np.absolute(w2))
Log.add('finished.', Severity.INFO)
return _np.abs(evals2_sorted[1])
示例11: getFiedlerVectorDense
# 需要導入模塊: import scipy [as 別名]
# 或者: from scipy import absolute [as 別名]
def getFiedlerVectorDense(self):
"""
Returns the (dense)Fiedler vector of the higher-order network. The Fiedler
vector can be used for a spectral bisectioning of the network.
"""
# NOTE: The Laplacian is transposed for the sparse case to get the left
# NOTE: eigenvalue.
L = self.getLaplacianMatrix()
# convert to dense matrix and transpose again to have the untransposed
# laplacian again.
w, v = _la.eig(L.todense().transpose(), right=False, left=True)
return v[:,_np.argsort(_np.absolute(w))][:,1]
示例12: get_amplitude
# 需要導入模塊: import scipy [as 別名]
# 或者: from scipy import absolute [as 別名]
def get_amplitude(self,signal,l):
if self.amplitude.has_key(l):
return self.amplitude[l]
else:
amp = sp.absolute(sp.fft(get_frame(signal, self.winsize,l) * self.window))
self.amplitude[l] = amp
return amp
示例13: compute_noise_avg_spectrum
# 需要導入模塊: import scipy [as 別名]
# 或者: from scipy import absolute [as 別名]
def compute_noise_avg_spectrum(self, nsignal):
windownum = int(len(nsignal)//(self.winsize//2) - 1)
avgamp = np.zeros(self.winsize)
for l in range(windownum):
avgamp += sp.absolute(sp.fft(get_frame(nsignal, self.winsize,l) * self.window))
return avgamp/float(windownum)
示例14: __minowski_low_positive_integer_p
# 需要導入模塊: import scipy [as 別名]
# 或者: from scipy import absolute [as 別名]
def __minowski_low_positive_integer_p(h1, h2, p = 2): # 11..43 us for p = 1..24 \w 100 bins
"""
A faster implementation of the Minowski distance for positive integer < 25.
@note do not use this function directly, but the general @link minowski() method.
@note the passed histograms must be scipy arrays.
"""
mult = scipy.absolute(h1 - h2)
dif = mult
for _ in range(p - 1): dif = scipy.multiply(dif, mult)
return math.pow(scipy.sum(dif), 1./p)
示例15: __minowski_low_negative_integer_p
# 需要導入模塊: import scipy [as 別名]
# 或者: from scipy import absolute [as 別名]
def __minowski_low_negative_integer_p(h1, h2, p = 2): # 14..46 us for p = -1..-24 \w 100 bins
"""
A faster implementation of the Minowski distance for negative integer > -25.
@note do not use this function directly, but the general @link minowski() method.
@note the passed histograms must be scipy arrays.
"""
mult = scipy.absolute(h1 - h2)
dif = mult
for _ in range(-p + 1): dif = scipy.multiply(dif, mult)
return math.pow(scipy.sum(1./dif), 1./p)