当前位置: 首页>>代码示例>>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;未经允许,请勿转载。