當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。