當前位置: 首頁>>代碼示例>>Python>>正文


Python numpy.complexfloating方法代碼示例

本文整理匯總了Python中numpy.complexfloating方法的典型用法代碼示例。如果您正苦於以下問題:Python numpy.complexfloating方法的具體用法?Python numpy.complexfloating怎麽用?Python numpy.complexfloating使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在numpy的用法示例。


在下文中一共展示了numpy.complexfloating方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_basic_property

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import complexfloating [as 別名]
def test_basic_property(self):
        # Check A = L L^H
        shapes = [(1, 1), (2, 2), (3, 3), (50, 50), (3, 10, 10)]
        dtypes = (np.float32, np.float64, np.complex64, np.complex128)

        for shape, dtype in itertools.product(shapes, dtypes):
            np.random.seed(1)
            a = np.random.randn(*shape)
            if np.issubdtype(dtype, np.complexfloating):
                a = a + 1j*np.random.randn(*shape)

            t = list(range(len(shape)))
            t[-2:] = -1, -2

            a = np.matmul(a.transpose(t).conj(), a)
            a = np.asarray(a, dtype=dtype)

            c = np.linalg.cholesky(a)

            b = np.matmul(c, c.transpose(t).conj())
            assert_allclose(b, a,
                            err_msg="{} {}\n{}\n{}".format(shape, dtype, a, c),
                            atol=500 * a.shape[0] * np.finfo(dtype).eps) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:25,代碼來源:test_linalg.py

示例2: check_arguments

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import complexfloating [as 別名]
def check_arguments(fun, y0, support_complex):
    """Helper function for checking arguments common to all solvers."""
    y0 = np.asarray(y0)
    if np.issubdtype(y0.dtype, np.complexfloating):
        if not support_complex:
            raise ValueError("`y0` is complex, but the chosen solver does "
                             "not support integration in a complex domain.")
        dtype = complex
    else:
        dtype = float
    y0 = y0.astype(dtype, copy=False)

    if y0.ndim != 1:
        raise ValueError("`y0` must be 1-dimensional.")

    def fun_wrapped(t, y):
        return np.asarray(fun(t, y), dtype=dtype)

    return fun_wrapped, y0 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:21,代碼來源:base.py

示例3: get_test_array

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import complexfloating [as 別名]
def get_test_array(shape, tp, val_range=None):
    dtype = tp_dtype(tp)
    if val_range is None:
        nmin, nmax = tp_limits(tp)
    else:
        nmin, nmax = val_range

    if numpy.issubdtype(dtype, numpy.integer):
        return numpy.random.randint(nmin, nmax, dtype=dtype, size=shape)
    elif numpy.issubdtype(dtype, numpy.floating):
        return numpy.random.uniform(nmin, nmax, size=shape).astype(dtype)
    elif numpy.issubdtype(dtype, numpy.complexfloating):
        return (
            numpy.random.uniform(nmin, nmax, size=shape)
            + 1j * numpy.random.uniform(nmin, nmax, size=shape)).astype(dtype)
    else:
        raise NotImplementedError(dtype) 
開發者ID:nucypher,項目名稱:nufhe,代碼行數:19,代碼來源:utils.py

示例4: _check_1d

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import complexfloating [as 別名]
def _check_1d(self, routine, dtype, shape, axis, overwritable_dtypes):
        np.random.seed(1234)
        if np.issubdtype(dtype, np.complexfloating):
            data = np.random.randn(*shape) + 1j*np.random.randn(*shape)
        else:
            data = np.random.randn(*shape)
        data = data.astype(dtype)

        for type in [1, 2, 3]:
            for overwrite_x in [True, False]:
                for norm in [None, 'ortho']:
                    if type == 1 and norm == 'ortho':
                        continue

                    should_overwrite = (overwrite_x
                                        and dtype in overwritable_dtypes
                                        and (len(shape) == 1 or
                                             (axis % len(shape) == len(shape)-1
                                              )))
                    self._check(data, routine, type, None, axis, norm,
                                overwrite_x, should_overwrite) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:23,代碼來源:test_real_transforms.py

示例5: _check_1d

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import complexfloating [as 別名]
def _check_1d(self, routine, dtype, shape, axis, overwritable_dtypes):
        np.random.seed(1234)
        if np.issubdtype(dtype, np.complexfloating):
            data = np.random.randn(*shape) + 1j*np.random.randn(*shape)
        else:
            data = np.random.randn(*shape)
        data = data.astype(dtype)

        for fftsize in [8, 16, 32]:
            for overwrite_x in [True, False]:
                should_overwrite = (overwrite_x
                                    and dtype in overwritable_dtypes
                                    and fftsize <= shape[axis]
                                    and (len(shape) == 1 or
                                         (axis % len(shape) == len(shape)-1
                                          and fftsize == shape[axis])))
                self._check(data, routine, fftsize, axis,
                            overwrite_x=overwrite_x,
                            should_overwrite=should_overwrite) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:21,代碼來源:test_basic.py

示例6: test_mu

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import complexfloating [as 別名]
def test_mu(self):
        self.__arith_init()

        # basic tests
        assert_array_equal((self.__Asp*self.__Bsp.T).todense(),self.__A*self.__B.T)

        for x in supported_dtypes:
            A = self.__A.astype(x)
            Asp = self.spmatrix(A)
            for y in supported_dtypes:
                if np.issubdtype(y, np.complexfloating):
                    B = self.__B.astype(y)
                else:
                    B = self.__B.real.astype(y)
                Bsp = self.spmatrix(B)

                D1 = A * B.T
                S1 = Asp * Bsp.T

                assert_array_equal(S1.todense(),D1)
                assert_equal(S1.dtype,D1.dtype) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:23,代碼來源:test_base.py

示例7: __init__

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import complexfloating [as 別名]
def __init__(self, scipy_func, mpmath_func, arg_spec, name=None,
                 dps=None, prec=None, n=5000, rtol=1e-7, atol=1e-300,
                 ignore_inf_sign=False):
        self.scipy_func = scipy_func
        self.mpmath_func = mpmath_func
        self.arg_spec = arg_spec
        self.dps = dps
        self.prec = prec
        self.n = n
        self.rtol = rtol
        self.atol = atol
        self.ignore_inf_sign = ignore_inf_sign
        if isinstance(self.arg_spec, np.ndarray):
            self.is_complex = np.issubdtype(self.arg_spec.dtype, np.complexfloating)
        else:
            self.is_complex = any([isinstance(arg, ComplexArg) for arg in self.arg_spec])
        self.ignore_inf_sign = ignore_inf_sign
        if not name or name == '<lambda>':
            name = getattr(scipy_func, '__name__', None)
        if not name or name == '<lambda>':
            name = getattr(mpmath_func, '__name__', None)
        self.name = name 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:24,代碼來源:test_mpmath.py

示例8: _rand_dtype

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import complexfloating [as 別名]
def _rand_dtype(rand, shape, dtype, scale=1., post=lambda x: x):
  """Produce random values given shape, dtype, scale, and post-processor.

  Args:
    rand: a function for producing random values of a given shape, e.g. a
      bound version of either onp.RandomState.randn or onp.RandomState.rand.
    shape: a shape value as a tuple of positive integers.
    dtype: a numpy dtype.
    scale: optional, a multiplicative scale for the random values (default 1).
    post: optional, a callable for post-processing the random values (default
      identity).

  Returns:
    An ndarray of the given shape and dtype using random values based on a call
    to rand but scaled, converted to the appropriate dtype, and post-processed.
  """
  r = lambda: onp.asarray(scale * rand(*_dims_of_shape(shape)), dtype)
  if onp.issubdtype(dtype, onp.complexfloating):
    vals = r() + 1.0j * r()
  else:
    vals = r()
  return _cast_to_shape(onp.asarray(post(vals), dtype), shape, dtype) 
開發者ID:google,項目名稱:trax,代碼行數:24,代碼來源:test_util.py

示例9: real

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import complexfloating [as 別名]
def real(self):
        ret_type = numpy.real(numpy.zeros((),dtype=self.dtype)).dtype
        shape = list(self.shape)
        if not numpy.issubdtype(self.dtype, numpy.complexfloating):
            return self

        shape[-1] *= 2
        dims = numpy.array(pu.c2f(shape),dtype=pu.dim_t)
        s = arrayfire.Array()
        arrayfire.backend.get().af_device_array(ctypes.pointer(s.arr),
                                                ctypes.c_void_p(self.d_array.device_ptr()),
                                                self.ndim,
                                                ctypes.c_void_p(dims.ctypes.data),
                                                pu.typemap(ret_type).value)
        arrayfire.backend.get().af_retain_array(ctypes.pointer(s.arr),s.arr)
        a = ndarray(shape, dtype=ret_type, af_array=s)
        ret = a[...,::2]
        ret._base = a
        ret._base_index = (Ellipsis, slice(None,None,2))
        return ret 
開發者ID:FilipeMaia,項目名稱:afnumpy,代碼行數:22,代碼來源:multiarray.py

示例10: imag

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import complexfloating [as 別名]
def imag(self):
        ret_type = numpy.real(numpy.zeros((),dtype=self.dtype)).dtype
        shape = list(self.shape)
        if not numpy.issubdtype(self.dtype, numpy.complexfloating):
            return afnumpy.zeros(self.shape)
        shape[-1] *= 2
        dims = numpy.array(pu.c2f(shape),dtype=pu.dim_t)
        s = arrayfire.Array()
        arrayfire.backend.get().af_device_array(ctypes.pointer(s.arr),
                                                ctypes.c_void_p(self.d_array.device_ptr()),
                                                self.ndim,
                                                ctypes.c_void_p(dims.ctypes.data),
                                                pu.typemap(ret_type).value)
        arrayfire.backend.get().af_retain_array(ctypes.pointer(s.arr),s.arr)
        a = ndarray(shape, dtype=ret_type, af_array=s)
        ret = a[...,1::2]
        ret._base = a
        ret._base_index = (Ellipsis, slice(1,None,2))
        return ret 
開發者ID:FilipeMaia,項目名稱:afnumpy,代碼行數:21,代碼來源:multiarray.py

示例11: conj

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import complexfloating [as 別名]
def conj(self, copy=True):
        """Element-wise complex conjugation.

        If the matrix is of non-complex data type and `copy` is False,
        this method does nothing and the data is not copied.

        Parameters
        ----------
        copy : bool, optional
            If True, the result is guaranteed to not share data with self.

        Returns
        -------
        A : The element-wise complex conjugate.

        """
        if np.issubdtype(self.dtype, np.complexfloating):
            return self.tocsr(copy=copy).conj(copy=False)
        elif copy:
            return self.copy()
        else:
            return self 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:24,代碼來源:base.py

示例12: test_mu

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import complexfloating [as 別名]
def test_mu(self):
        self.__arith_init()

        # basic tests
        assert_array_equal((self.__Asp*self.__Bsp.T).todense(),self.__A*self.__B.T)

        for x in supported_dtypes:
            A = self.__A.astype(x)
            Asp = self.spmatrix(A)
            for y in supported_dtypes:
                if np.issubdtype(y, np.complexfloating):
                    B = self.__B.astype(y)
                else:
                    B = self.__B.real.astype(y)
                Bsp = self.spmatrix(B)

                D1 = A * B.T
                S1 = Asp * Bsp.T

                assert_allclose(S1.todense(), D1,
                                atol=1e-14*abs(D1).max())
                assert_equal(S1.dtype,D1.dtype) 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:24,代碼來源:test_base.py

示例13: test_dtype_cast

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import complexfloating [as 別名]
def test_dtype_cast(self):
        A_real = scipy.sparse.csr_matrix([[1, 2, 0],
                                          [0, 0, 3],
                                          [4, 0, 5]])
        A_complex = scipy.sparse.csr_matrix([[1, 2, 0],
                                             [0, 0, 3],
                                             [4, 0, 5 + 1j]])
        b_real = np.array([1,1,1])
        b_complex = np.array([1,1,1]) + 1j*np.array([1,1,1])
        x = spsolve(A_real, b_real)
        assert_(np.issubdtype(x.dtype, np.floating))
        x = spsolve(A_real, b_complex)
        assert_(np.issubdtype(x.dtype, np.complexfloating))
        x = spsolve(A_complex, b_real)
        assert_(np.issubdtype(x.dtype, np.complexfloating))
        x = spsolve(A_complex, b_complex)
        assert_(np.issubdtype(x.dtype, np.complexfloating)) 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:19,代碼來源:test_linsolve.py

示例14: _get_format_function

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import complexfloating [as 別名]
def _get_format_function(data, **options):
    """
    find the right formatting function for the dtype_
    """
    dtype_ = data.dtype
    dtypeobj = dtype_.type
    formatdict = _get_formatdict(data, **options)
    if issubclass(dtypeobj, _nt.bool_):
        return formatdict['bool']()
    elif issubclass(dtypeobj, _nt.integer):
        if issubclass(dtypeobj, _nt.timedelta64):
            return formatdict['timedelta']()
        else:
            return formatdict['int']()
    elif issubclass(dtypeobj, _nt.floating):
        if issubclass(dtypeobj, _nt.longfloat):
            return formatdict['longfloat']()
        else:
            return formatdict['float']()
    elif issubclass(dtypeobj, _nt.complexfloating):
        if issubclass(dtypeobj, _nt.clongfloat):
            return formatdict['longcomplexfloat']()
        else:
            return formatdict['complexfloat']()
    elif issubclass(dtypeobj, (_nt.unicode_, _nt.string_)):
        return formatdict['numpystr']()
    elif issubclass(dtypeobj, _nt.datetime64):
        return formatdict['datetime']()
    elif issubclass(dtypeobj, _nt.object_):
        return formatdict['object']()
    elif issubclass(dtypeobj, _nt.void):
        if dtype_.names is not None:
            return StructuredVoidFormat.from_data(data, **options)
        else:
            return formatdict['void']()
    else:
        return formatdict['numpystr']() 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:39,代碼來源:arrayprint.py

示例15: test_abstract

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import complexfloating [as 別名]
def test_abstract(self):
        assert_(issubclass(np.number, numbers.Number))

        assert_(issubclass(np.inexact, numbers.Complex))
        assert_(issubclass(np.complexfloating, numbers.Complex))
        assert_(issubclass(np.floating, numbers.Real))

        assert_(issubclass(np.integer, numbers.Integral))
        assert_(issubclass(np.signedinteger, numbers.Integral))
        assert_(issubclass(np.unsignedinteger, numbers.Integral)) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:12,代碼來源:test_abc.py


注:本文中的numpy.complexfloating方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。