本文整理汇总了Python中numpy.fft方法的典型用法代码示例。如果您正苦于以下问题:Python numpy.fft方法的具体用法?Python numpy.fft怎么用?Python numpy.fft使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类numpy
的用法示例。
在下文中一共展示了numpy.fft方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _freq
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import fft [as 别名]
def _freq(N, delta_x, real, shift):
# calculate frequencies from coordinates
# coordinates are always loaded eagerly, so we use numpy
if real is None:
fftfreq = [np.fft.fftfreq]*len(N)
else:
# Discard negative frequencies from transform along last axis to be
# consistent with np.fft.rfftn
fftfreq = [np.fft.fftfreq]*(len(N)-1)
fftfreq.append(np.fft.rfftfreq)
k = [fftfreq(Nx, dx) for (fftfreq, Nx, dx) in zip(fftfreq, N, delta_x)]
if shift:
k = [np.fft.fftshift(l) for l in k]
return k
示例2: make_node
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import fft [as 别名]
def make_node(self, frames, n, axis):
"""
Compute an n-point fft of frames along given axis.
"""
_frames = tensor.as_tensor(frames, ndim=2)
_n = tensor.as_tensor(n, ndim=0)
_axis = tensor.as_tensor(axis, ndim=0)
if self.half and _frames.type.dtype.startswith('complex'):
raise TypeError('Argument to HalfFFT must not be complex', frames)
spectrogram = tensor.zmatrix()
buf = generic()
# The `buf` output is present for future work
# when we call FFTW directly and re-use the 'plan' that FFTW creates.
# In that case, buf would store a CObject encapsulating the plan.
rval = Apply(self, [_frames, _n, _axis], [spectrogram, buf])
return rval
示例3: perform
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import fft [as 别名]
def perform(self, node, inp, out):
frames, n, axis = inp
spectrogram, buf = out
if self.inverse:
fft_fn = numpy.fft.ifft
else:
fft_fn = numpy.fft.fft
fft = fft_fn(frames, int(n), int(axis))
if self.half:
M, N = fft.shape
if axis == 0:
if (M % 2):
raise ValueError(
'halfFFT on odd-length vectors is undefined')
spectrogram[0] = fft[0:M / 2, :]
elif axis == 1:
if (N % 2):
raise ValueError(
'halfFFT on odd-length vectors is undefined')
spectrogram[0] = fft[:, 0:N / 2]
else:
raise NotImplementedError()
else:
spectrogram[0] = fft
示例4: test_size_accuracy
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import fft [as 别名]
def test_size_accuracy(self):
# Sanity check for the accuracy for prime and non-prime sized inputs
if self.rdt == np.float32:
rtol = 1e-5
elif self.rdt == np.float64:
rtol = 1e-10
for size in LARGE_COMPOSITE_SIZES + LARGE_PRIME_SIZES:
np.random.seed(1234)
x = np.random.rand(size).astype(self.rdt)
y = ifft(fft(x))
self.assertTrue(np.linalg.norm(x - y) < rtol*np.linalg.norm(x),
(size, self.rdt))
y = fft(ifft(x))
self.assertTrue(np.linalg.norm(x - y) < rtol*np.linalg.norm(x),
(size, self.rdt))
x = (x + 1j*np.random.rand(size)).astype(self.cdt)
y = ifft(fft(x))
self.assertTrue(np.linalg.norm(x - y) < rtol*np.linalg.norm(x),
(size, self.rdt))
y = fft(ifft(x))
self.assertTrue(np.linalg.norm(x - y) < rtol*np.linalg.norm(x),
(size, self.rdt))
示例5: test_fft
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import fft [as 别名]
def test_fft():
b = numpy.random.random((3,3))
a = afnumpy.array(b)
fassert(afnumpy.fft.fft(a), numpy.fft.fft(b))
b = numpy.random.random((3,2))
a = afnumpy.array(b)
fassert(afnumpy.fft.fft(a), numpy.fft.fft(b))
b = numpy.random.random((5,3,2))
a = afnumpy.array(b)
fassert(afnumpy.fft.fft(a), numpy.fft.fft(b))
b = numpy.random.random((5,3,2))+numpy.random.random((5,3,2))*1.0j
a = afnumpy.array(b)
fassert(afnumpy.fft.fft(a), numpy.fft.fft(b))
示例6: test_ifft
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import fft [as 别名]
def test_ifft():
# Real to complex inverse fft not implemented in arrayfire
# b = numpy.random.random((3,3))
# a = afnumpy.array(b)
# fassert(afnumpy.fft.ifft(a), numpy.fft.ifft(b))
# b = numpy.random.random((3,2))
# a = afnumpy.array(b)
# fassert(afnumpy.fft.ifft(a), numpy.fft.ifft(b))
# b = numpy.random.random((5,3,2))
# a = afnumpy.array(b)
# fassert(afnumpy.fft.ifft(a), numpy.fft.ifft(b))
b = numpy.random.random((5,3,2))+numpy.random.random((5,3,2))*1.0j
# b = numpy.ones((3,3))+numpy.zeros((3,3))*1.0j
a = afnumpy.array(b)
fassert(afnumpy.fft.ifft(a), numpy.fft.ifft(b))
示例7: test_fft2
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import fft [as 别名]
def test_fft2():
b = numpy.random.random((3,3))
a = afnumpy.array(b)
fassert(afnumpy.fft.fft2(a), numpy.fft.fft2(b))
b = numpy.random.random((3,2))
a = afnumpy.array(b)
fassert(afnumpy.fft.fft2(a), numpy.fft.fft2(b))
b = numpy.random.random((5,3,2))
a = afnumpy.array(b)
fassert(afnumpy.fft.fft2(a), numpy.fft.fft2(b))
b = numpy.random.random((5,3,2))+numpy.random.random((5,3,2))*1.0j
a = afnumpy.array(b)
fassert(afnumpy.fft.fft2(a), numpy.fft.fft2(b))
示例8: test_ifft2
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import fft [as 别名]
def test_ifft2():
# Real to complex inverse fft not implemented in arrayfire
# b = numpy.random.random((3,3))
# a = afnumpy.array(b)
# fassert(afnumpy.fft.ifft2(a), numpy.fft.ifft2(b))
# b = numpy.random.random((3,2))
# a = afnumpy.array(b)
# fassert(afnumpy.fft.ifft2(a), numpy.fft.ifft2(b))
# b = numpy.random.random((5,3,2))
# a = afnumpy.array(b)
# fassert(afnumpy.fft.ifft2(a), numpy.fft.ifft2(b))
b = numpy.random.random((5,3,2))+numpy.random.random((5,3,2))*1.0j
# b = numpy.ones((3,3))+numpy.zeros((3,3))*1.0j
a = afnumpy.array(b)
fassert(afnumpy.fft.ifft2(a), numpy.fft.ifft2(b))
示例9: test_shape_axes_argument
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import fft [as 别名]
def test_shape_axes_argument(self):
small_x = [[1,2,3],[4,5,6],[7,8,9]]
large_x1 = array([[1,2,3,0],
[4,5,6,0],
[7,8,9,0],
[0,0,0,0]])
# Disable tests with shape and axes of different lengths
# y = fftn(small_x,shape=(4,4),axes=(-1,))
# for i in range(4):
# assert_array_almost_equal (y[i],fft(large_x1[i]))
# y = fftn(small_x,shape=(4,4),axes=(-2,))
# for i in range(4):
# assert_array_almost_equal (y[:,i],fft(large_x1[:,i]))
y = fftn(small_x,shape=(4,4),axes=(-2,-1))
assert_array_almost_equal(y,fftn(large_x1))
y = fftn(small_x,shape=(4,4),axes=(-1,-2))
assert_array_almost_equal(y,swapaxes(
fftn(swapaxes(large_x1,-1,-2)),-1,-2))
示例10: _fft_module
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import fft [as 别名]
def _fft_module(da):
if da.chunks:
return dsar.fft
else:
return np.fft
示例11: isotropize
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import fft [as 别名]
def isotropize(ps, fftdim, nfactor=4):
"""
Isotropize a 2D power spectrum or cross spectrum
by taking an azimuthal average.
.. math::
\text{iso}_{ps} = k_r N^{-1} \sum_{N} |\mathbb{F}(da')|^2
where :math:`N` is the number of azimuthal bins.
Parameters
----------
ps : `xarray.DataArray`
The power spectrum or cross spectrum to be isotropized.
fftdim : list
The fft dimensions overwhich the isotropization must be performed.
nfactor : int, optional
Ratio of number of bins to take the azimuthal averaging with the
data size. Default is 4.
"""
# compute radial wavenumber bins
k = ps[fftdim[1]]
l = ps[fftdim[0]]
N = [k.size, l.size]
ki, kr = _radial_wvnum(k, l, min(N), nfactor)
# average azimuthally
ps = ps.assign_coords(freq_r=np.sqrt(k**2+l**2))
iso_ps = (ps.groupby_bins('freq_r', bins=ki, labels=kr).mean()
.rename({'freq_r_bins': 'freq_r'})
)
return iso_ps * iso_ps.freq_r
示例12: _fftn_blas
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import fft [as 别名]
def _fftn_blas(f, mesh):
Gx = np.fft.fftfreq(mesh[0])
Gy = np.fft.fftfreq(mesh[1])
Gz = np.fft.fftfreq(mesh[2])
expRGx = np.exp(np.einsum('x,k->xk', -2j*np.pi*np.arange(mesh[0]), Gx))
expRGy = np.exp(np.einsum('x,k->xk', -2j*np.pi*np.arange(mesh[1]), Gy))
expRGz = np.exp(np.einsum('x,k->xk', -2j*np.pi*np.arange(mesh[2]), Gz))
out = np.empty(f.shape, dtype=np.complex128)
buf = np.empty(mesh, dtype=np.complex128)
for i, fi in enumerate(f):
buf[:] = fi.reshape(mesh)
g = lib.dot(buf.reshape(mesh[0],-1).T, expRGx, c=out[i].reshape(-1,mesh[0]))
g = lib.dot(g.reshape(mesh[1],-1).T, expRGy, c=buf.reshape(-1,mesh[1]))
g = lib.dot(g.reshape(mesh[2],-1).T, expRGz, c=out[i].reshape(-1,mesh[2]))
return out.reshape(-1, *mesh)
示例13: _ifftn_blas
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import fft [as 别名]
def _ifftn_blas(g, mesh):
Gx = np.fft.fftfreq(mesh[0])
Gy = np.fft.fftfreq(mesh[1])
Gz = np.fft.fftfreq(mesh[2])
expRGx = np.exp(np.einsum('x,k->xk', 2j*np.pi*np.arange(mesh[0]), Gx))
expRGy = np.exp(np.einsum('x,k->xk', 2j*np.pi*np.arange(mesh[1]), Gy))
expRGz = np.exp(np.einsum('x,k->xk', 2j*np.pi*np.arange(mesh[2]), Gz))
out = np.empty(g.shape, dtype=np.complex128)
buf = np.empty(mesh, dtype=np.complex128)
for i, gi in enumerate(g):
buf[:] = gi.reshape(mesh)
f = lib.dot(buf.reshape(mesh[0],-1).T, expRGx, 1./mesh[0], c=out[i].reshape(-1,mesh[0]))
f = lib.dot(f.reshape(mesh[1],-1).T, expRGy, 1./mesh[1], c=buf.reshape(-1,mesh[1]))
f = lib.dot(f.reshape(mesh[2],-1).T, expRGz, 1./mesh[2], c=out[i].reshape(-1,mesh[2]))
return out.reshape(-1, *mesh)
示例14: _fftn_wrapper
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import fft [as 别名]
def _fftn_wrapper(a):
return np.fft.fftn(a, axes=(1,2,3))
示例15: _ifftn_wrapper
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import fft [as 别名]
def _ifftn_wrapper(a):
return np.fft.ifftn(a, axes=(1,2,3))