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


Python fftpack.fftn方法代码示例

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


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

示例1: test_size_accuracy

# 需要导入模块: from scipy import fftpack [as 别名]
# 或者: from scipy.fftpack import fftn [as 别名]
def test_size_accuracy(self):
        for size in SMALL_COMPOSITE_SIZES + SMALL_PRIME_SIZES:
            np.random.seed(1234)
            x = np.random.rand(size, size) + 1j*np.random.rand(size, size)
            y1 = fftn(x.real.astype(np.float32))
            y2 = fftn(x.real.astype(np.float64)).astype(np.complex64)

            self.assertTrue(y1.dtype == np.complex64)
            assert_array_almost_equal_nulp(y1, y2, 2000)

        for size in LARGE_COMPOSITE_SIZES + LARGE_PRIME_SIZES:
            np.random.seed(1234)
            x = np.random.rand(size, 3) + 1j*np.random.rand(size, 3)
            y1 = fftn(x.real.astype(np.float32))
            y2 = fftn(x.real.astype(np.float64)).astype(np.complex64)

            self.assertTrue(y1.dtype == np.complex64)
            assert_array_almost_equal_nulp(y1, y2, 2000) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:20,代码来源:test_basic.py

示例2: test_shape_axes_argument

# 需要导入模块: from scipy import fftpack [as 别名]
# 或者: from scipy.fftpack import fftn [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)) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:20,代码来源:test_basic.py

示例3: test_size_accuracy

# 需要导入模块: from scipy import fftpack [as 别名]
# 或者: from scipy.fftpack import fftn [as 别名]
def test_size_accuracy(self):
        for size in SMALL_COMPOSITE_SIZES + SMALL_PRIME_SIZES:
            np.random.seed(1234)
            x = np.random.rand(size, size) + 1j*np.random.rand(size, size)
            y1 = fftn(x.real.astype(np.float32))
            y2 = fftn(x.real.astype(np.float64)).astype(np.complex64)

            assert_equal(y1.dtype, np.complex64)
            assert_array_almost_equal_nulp(y1, y2, 2000)

        for size in LARGE_COMPOSITE_SIZES + LARGE_PRIME_SIZES:
            np.random.seed(1234)
            x = np.random.rand(size, 3) + 1j*np.random.rand(size, 3)
            y1 = fftn(x.real.astype(np.float32))
            y2 = fftn(x.real.astype(np.float64)).astype(np.complex64)

            assert_equal(y1.dtype, np.complex64)
            assert_array_almost_equal_nulp(y1, y2, 2000) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:20,代码来源:test_basic.py

示例4: test_float16_input

# 需要导入模块: from scipy import fftpack [as 别名]
# 或者: from scipy.fftpack import fftn [as 别名]
def test_float16_input(self):
        for size in SMALL_COMPOSITE_SIZES + SMALL_PRIME_SIZES:
            np.random.seed(1234)
            x = np.random.rand(size, size) + 1j*np.random.rand(size, size)
            y1 = fftn(x.real.astype(np.float16))
            y2 = fftn(x.real.astype(np.float64)).astype(np.complex64)

            assert_equal(y1.dtype, np.complex64)
            assert_array_almost_equal_nulp(y1, y2, 5e5)

        for size in LARGE_COMPOSITE_SIZES + LARGE_PRIME_SIZES:
            np.random.seed(1234)
            x = np.random.rand(size, 3) + 1j*np.random.rand(size, 3)
            y1 = fftn(x.real.astype(np.float16))
            y2 = fftn(x.real.astype(np.float64)).astype(np.complex64)

            assert_equal(y1.dtype, np.complex64)
            assert_array_almost_equal_nulp(y1, y2, 2e6) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:20,代码来源:test_basic.py

示例5: get_numpy

# 需要导入模块: from scipy import fftpack [as 别名]
# 或者: from scipy.fftpack import fftn [as 别名]
def get_numpy(shape, fftn_shape=None, **kwargs):
    import numpy.fft as numpy_fft

    f = {
        "fft2": numpy_fft.fft2,
        "ifft2": numpy_fft.ifft2,
        "rfft2": numpy_fft.rfft2,
        "irfft2": lambda X: numpy_fft.irfft2(X, s=shape),
        "fftshift": numpy_fft.fftshift,
        "ifftshift": numpy_fft.ifftshift,
        "fftfreq": numpy_fft.fftfreq,
    }
    if fftn_shape is not None:
        f["fftn"] = numpy_fft.fftn
    fft = SimpleNamespace(**f)

    return fft 
开发者ID:pySTEPS,项目名称:pysteps,代码行数:19,代码来源:fft.py

示例6: get_scipy

# 需要导入模块: from scipy import fftpack [as 别名]
# 或者: from scipy.fftpack import fftn [as 别名]
def get_scipy(shape, fftn_shape=None, **kwargs):
    import numpy.fft as numpy_fft
    import scipy.fftpack as scipy_fft

    # use numpy implementation of rfft2/irfft2 because they have not been
    # implemented in scipy.fftpack
    f = {
        "fft2": scipy_fft.fft2,
        "ifft2": scipy_fft.ifft2,
        "rfft2": numpy_fft.rfft2,
        "irfft2": lambda X: numpy_fft.irfft2(X, s=shape),
        "fftshift": scipy_fft.fftshift,
        "ifftshift": scipy_fft.ifftshift,
        "fftfreq": scipy_fft.fftfreq,
    }
    if fftn_shape is not None:
        f["fftn"] = scipy_fft.fftn
    fft = SimpleNamespace(**f)

    return fft 
开发者ID:pySTEPS,项目名称:pysteps,代码行数:22,代码来源:fft.py

示例7: vhartree_pbc

# 需要导入模块: from scipy import fftpack [as 别名]
# 或者: from scipy.fftpack import fftn [as 别名]
def vhartree_pbc(self, dens, **kw): 
  """  Compute Hartree potential for the density given in an equidistant grid  """
  from scipy.fftpack import fftn, ifftn
  sh = self.mesh3d.shape
  dens = dens.reshape(sh)
  vh = fftn(dens)    
  umom = self.ucell_mom()
  ii = [np.array([i-sh[j] if i>sh[j]//2 else i for i in range(sh[j])]) for j in range(3)]
  gg = [np.array([umom[j]*i for i in ii[j]]) for j in range(3)]
  vh = apply_inv_G2(vh, gg[0], gg[1], gg[2])
  vh = ifftn(vh).real*(4*np.pi)
  return vh 
开发者ID:pyscf,项目名称:pyscf,代码行数:14,代码来源:m_vhartree_pbc.py

示例8: _rfftn

# 需要导入模块: from scipy import fftpack [as 别名]
# 或者: from scipy.fftpack import fftn [as 别名]
def _rfftn(a, s=None, axes=None):
    return fft.fftn(a, shape = s, axes = axes); 
开发者ID:ChristophKirst,项目名称:ClearMap,代码行数:4,代码来源:Convolution.py

示例9: _pad_nans

# 需要导入模块: from scipy import fftpack [as 别名]
# 或者: from scipy.fftpack import fftn [as 别名]
def _pad_nans(x, head=None, tail=None):
    if np.ndim(x) == 1:
        if head is None and tail is None:
            return x
        elif head and tail:
            return np.r_[[np.nan] * head, x, [np.nan] * tail]
        elif tail is None:
            return np.r_[[np.nan] * head, x]
        elif head is None:
            return np.r_[x, [np.nan] * tail]
    elif np.ndim(x) == 2:
        if head is None and tail is None:
            return x
        elif head and tail:
            return np.r_[[[np.nan] * x.shape[1]] * head, x,
                         [[np.nan] * x.shape[1]] * tail]
        elif tail is None:
            return np.r_[[[np.nan] * x.shape[1]] * head, x]
        elif head is None:
            return np.r_[x, [[np.nan] * x.shape[1]] * tail]
    else:
        raise ValueError("Nan-padding for ndim > 2 not implemented")

#original changes and examples in sandbox.tsa.try_var_convolve

# don't do these imports, here just for copied fftconvolve
#get rid of these imports
#from scipy.fftpack import fft, ifft, ifftshift, fft2, ifft2, fftn, \
#     ifftn, fftfreq
#from numpy import product,array 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:32,代码来源:filtertools.py

示例10: bench_random

# 需要导入模块: from scipy import fftpack [as 别名]
# 或者: from scipy.fftpack import fftn [as 别名]
def bench_random(self):
        from numpy.fft import fftn as numpy_fftn
        print()
        print('    Multi-dimensional Fast Fourier Transform')
        print('===================================================')
        print('          |    real input     |   complex input    ')
        print('---------------------------------------------------')
        print('   size   |  scipy  |  numpy  |  scipy  |  numpy ')
        print('---------------------------------------------------')
        for size,repeat in [((100,100),100),((1000,100),7),
                            ((256,256),10),
                            ((512,512),3),
                            ]:
            print('%9s' % ('%sx%s' % size), end=' ')
            sys.stdout.flush()

            for x in [random(size).astype(double),
                      random(size).astype(cdouble)+random(size).astype(cdouble)*1j
                      ]:
                y = fftn(x)
                #if size > 500: y = fftn(x)
                #else: y = direct_dft(x)
                assert_array_almost_equal(fftn(x),y)
                print('|%8.2f' % measure('fftn(x)',repeat), end=' ')
                sys.stdout.flush()

                assert_array_almost_equal(numpy_fftn(x),y)
                print('|%8.2f' % measure('numpy_fftn(x)',repeat), end=' ')
                sys.stdout.flush()

            print(' (secs for %s calls)' % (repeat))

        sys.stdout.flush() 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:35,代码来源:bench_basic.py

示例11: test_regression_244

# 需要导入模块: from scipy import fftpack [as 别名]
# 或者: from scipy.fftpack import fftn [as 别名]
def test_regression_244(self):
        """fft returns wrong result with axes parameter."""
        # fftn (and hence fft2) used to break when both axes and shape were
        # used
        x = numpy.ones((4,4,2))
        y = fft2(x, shape=(8,8), axes=(-3,-2))
        y_r = numpy.fft.fftn(x, s=(8, 8), axes=(-3, -2))
        assert_array_almost_equal(y, y_r) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:10,代码来源:test_basic.py

示例12: test_definition

# 需要导入模块: from scipy import fftpack [as 别名]
# 或者: from scipy.fftpack import fftn [as 别名]
def test_definition(self):
        x = [[1,2,3],[4,5,6],[7,8,9]]
        y = fftn(np.array(x, np.float32))
        if not y.dtype == np.complex64:
            raise ValueError("double precision output with single precision")

        y_r = np.array(fftn(x), np.complex64)
        assert_array_almost_equal_nulp(y, y_r) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:10,代码来源:test_basic.py

示例13: test_shape_axes_argument2

# 需要导入模块: from scipy import fftpack [as 别名]
# 或者: from scipy.fftpack import fftn [as 别名]
def test_shape_axes_argument2(self):
        # Change shape of the last axis
        x = numpy.random.random((10, 5, 3, 7))
        y = fftn(x, axes=(-1,), shape=(8,))
        assert_array_almost_equal(y, fft(x, axis=-1, n=8))

        # Change shape of an arbitrary axis which is not the last one
        x = numpy.random.random((10, 5, 3, 7))
        y = fftn(x, axes=(-2,), shape=(8,))
        assert_array_almost_equal(y, fft(x, axis=-2, n=8))

        # Change shape of axes: cf #244, where shape and axes were mixed up
        x = numpy.random.random((4,4,2))
        y = fftn(x, axes=(-3,-2), shape=(8,8))
        assert_array_almost_equal(y, numpy.fft.fftn(x, axes=(-3, -2), s=(8, 8))) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:17,代码来源:test_basic.py

示例14: test_shape_argument_more

# 需要导入模块: from scipy import fftpack [as 别名]
# 或者: from scipy.fftpack import fftn [as 别名]
def test_shape_argument_more(self):
        """Test that fftn raises ValueError when s.shape is longer than x.shape"""
        x = zeros((4, 4, 2))
        assert_raises(ValueError, fftn, x, shape=(8, 8, 2, 1)) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:6,代码来源:test_basic.py

示例15: test_random_complex

# 需要导入模块: from scipy import fftpack [as 别名]
# 或者: from scipy.fftpack import fftn [as 别名]
def test_random_complex(self):
        for size in [1,2,51,32,64,92]:
            x = random([size,size]) + 1j*random([size,size])
            assert_array_almost_equal_nulp(ifftn(fftn(x)),x,self.maxnlp)
            assert_array_almost_equal_nulp(fftn(ifftn(x)),x,self.maxnlp) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:7,代码来源:test_basic.py


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