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


Python scipy.special方法代碼示例

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


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

示例1: rel_entr

# 需要導入模塊: import scipy [as 別名]
# 或者: from scipy import special [as 別名]
def rel_entr(self, other):
        try:
            naked_other = naked(other)
        except TypeError:  # pragma: no cover
            return NotImplemented

        xp = get_array_module(self.spmatrix)

        if xp is np:
            from scipy.special import rel_entr
        else:  # pragma: no cover
            from cupyx.scipy.special import rel_entr

        if get_array_module(naked_other).isscalar(naked_other):  # pragma: no cover
            return call_sparse_binary_scalar(rel_entr, self, naked_other)
        else:
            if issparse(naked_other):  # pragma: no cover
                naked_other = other.toarray()
            x = get_sparse_module(self.spmatrix).csr_matrix(
                rel_entr(self.toarray(), naked_other))
        if issparse(x):
            return SparseNDArray(x, shape=self.shape)
        return get_array_module(x).asarray(x) 
開發者ID:mars-project,項目名稱:mars,代碼行數:25,代碼來源:array.py

示例2: cubic

# 需要導入模塊: import scipy [as 別名]
# 或者: from scipy import special [as 別名]
def cubic(x):
    """A cubic B-spline.

    This is a special case of `bspline`, and equivalent to ``bspline(x, 3)``.
    """
    ax = abs(asarray(x))
    res = zeros_like(ax)
    cond1 = less(ax, 1)
    if cond1.any():
        ax1 = ax[cond1]
        res[cond1] = 2.0 / 3 - 1.0 / 2 * ax1 ** 2 * (2 - ax1)
    cond2 = ~cond1 & less(ax, 2)
    if cond2.any():
        ax2 = ax[cond2]
        res[cond2] = 1.0 / 6 * (2 - ax2) ** 3
    return res 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:18,代碼來源:bsplines.py

示例3: quadratic

# 需要導入模塊: import scipy [as 別名]
# 或者: from scipy import special [as 別名]
def quadratic(x):
    """A quadratic B-spline.

    This is a special case of `bspline`, and equivalent to ``bspline(x, 2)``.
    """
    ax = abs(asarray(x))
    res = zeros_like(ax)
    cond1 = less(ax, 0.5)
    if cond1.any():
        ax1 = ax[cond1]
        res[cond1] = 0.75 - ax1 ** 2
    cond2 = ~cond1 & less(ax, 1.5)
    if cond2.any():
        ax2 = ax[cond2]
        res[cond2] = (ax2 - 1.5) ** 2 / 2.0
    return res 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:18,代碼來源:bsplines.py

示例4: fit_transform

# 需要導入模塊: import scipy [as 別名]
# 或者: from scipy import special [as 別名]
def fit_transform( self, X ):

        i = np.argsort( X, axis = 0 )
        j = np.argsort( i, axis = 0 )

        assert ( j.min() == 0 ).all()
        assert ( j.max() == len( j ) - 1 ).all()

        j_range = len( j ) - 1
        self.divider = j_range / self.range

        transformed = j / self.divider
        transformed = transformed - self.upper
        transformed = scipy.special.erfinv( transformed )
        ############
        # transformed = transformed - np.mean(transformed)

        return transformed 
開發者ID:rosetta-ai,項目名稱:rosetta_recsys2019,代碼行數:20,代碼來源:utils.py

示例5: __call__

# 需要導入模塊: import scipy [as 別名]
# 或者: from scipy import special [as 別名]
def __call__(self, n, k):
        if not isinstance(n, int):
            n = int(n)
        if not isinstance(k, int):
            k = int(k)

        res = 1.0
        if n < 0 or k < 0:
            return 0.0

        if k == 0:
            return res

        if (n - k) < k:
            return scipy.special.comb(n, n - k)

        for ix in xrange(k):
            res = (res * (n - ix)) / (k - ix)

        return res 
開發者ID:ufora,項目名稱:ufora,代碼行數:22,代碼來源:pure_scipy.py

示例6: test_typeWeCantTranslateYet_raise_4

# 需要導入模塊: import scipy [as 別名]
# 或者: from scipy import special [as 別名]
def test_typeWeCantTranslateYet_raise_4(self):
        import scipy
        def f():
            x = scipy.special
            return 0

        try:
            self.evaluateWithExecutor(f)
            self.assertTrue(False)
        except pyfora.ComputationError as e:
            self.assertTrue(
                str(e).startswith("Pyfora didn't know how to convert scipy.special")
                )
            self.assertIsInstance(
                e.remoteException,
                Exceptions.UnconvertibleValueError
                ) 
開發者ID:ufora,項目名稱:ufora,代碼行數:19,代碼來源:UnimplementedValuesTestCases.py

示例7: test_UnconvertibleValueErrorIsUncatchable

# 需要導入模塊: import scipy [as 別名]
# 或者: from scipy import special [as 別名]
def test_UnconvertibleValueErrorIsUncatchable(self):
        import scipy.special
        def f():
            try:
                return scipy.special.airy(0)
            except:
                return 0

        try:
            self.evaluateWithExecutor(f)
            self.assertTrue(False)
        except pyfora.ComputationError as e:
            self.assertIsInstance(
                e.remoteException,
                Exceptions.UnconvertibleValueError
                ) 
開發者ID:ufora,項目名稱:ufora,代碼行數:18,代碼來源:UnimplementedValuesTestCases.py

示例8: _convert

# 需要導入模塊: import scipy [as 別名]
# 或者: from scipy import special [as 別名]
def _convert(self, string):
        """
        Converts string in query to either a Parameter instance, a Numpy function, a scipy.special function or
        a float number.

        Args:
            string(str): string to convert

        Returns:
            Parameter instance, function or float
        """
        if string in self.names:
            param = [p for p in self.parameters if p.name == string][0]
            return param.copy()
        elif isinstance(string, str) and (string in dir(np)) and callable(getattr(np, string)):
            return getattr(np, string)
        elif isinstance(string, str) and (string in dir(sp)) and callable(getattr(sp, string)):
            return getattr(sp, string)
        else:
            return float(string) 
開發者ID:christophmark,項目名稱:bayesloop,代碼行數:22,代碼來源:parser.py

示例9: frequency

# 需要導入模塊: import scipy [as 別名]
# 或者: from scipy import special [as 別名]
def frequency(self, w, s=1.0):
        """Frequency representation of derivative of Gaussian.

        Parameters
        ----------
        w : float
            Angular frequency. If `s` is not specified, i.e. set to 1,
            this can be used as the non-dimensional angular
            frequency w * s.
        s : float
            Scaling factor. Default is 1.

        Returns
        -------
        out : complex
            Value of the derivative of Gaussian wavelet at the
            given time
        """
        m = self.m
        x = s * w
        gamma = scipy.special.gamma
        const = -1j ** m / gamma(m + 0.5) ** .5
        function = x ** m * np.exp(-x ** 2 / 2)
        return const * function 
開發者ID:hello-sea,項目名稱:DeepLearning_Wavelet-LSTM,代碼行數:26,代碼來源:my_wavelets.py

示例10: alpha_abs

# 需要導入模塊: import scipy [as 別名]
# 或者: from scipy import special [as 別名]
def alpha_abs(self, x, y, n_sersic, r_eff, k_eff, center_x=0, center_y=0):
        """

        :param x:
        :param y:
        :param n_sersic:
        :param r_eff:
        :param k_eff:
        :param center_x:
        :param center_y:
        :return:
        """
        n = n_sersic
        x_red = self._x_reduced(x, y, n_sersic, r_eff, center_x, center_y)
        b = self.b_n(n_sersic)
        a_eff = self._alpha_eff(r_eff, n_sersic, k_eff)
        alpha = 2. * a_eff * x_red ** (-n) * (special.gammainc(2 * n, b * x_red))
        return alpha 
開發者ID:sibirrer,項目名稱:lenstronomy,代碼行數:20,代碼來源:sersic_utils.py

示例11: test_function

# 需要導入模塊: import scipy [as 別名]
# 或者: from scipy import special [as 別名]
def test_function(name, specialization):
    if (name, specialization) in SKIP_LIST:
        pytest.xfail()

    scipy_func = getattr(sc, name)

    @numba.njit
    def numba_func(*args):
        return scipy_func(*args)

    args = itertools.product(*(
        NUMBA_TYPES_TO_TEST_POINTS[numba_type] for numba_type in specialization
    ))
    with warnings.catch_warnings():
        # Ignore warnings about unsafe casts generated by SciPy.
        warnings.filterwarnings(
            action='ignore',
            message='floating point number truncated to an integer',
            category=RuntimeWarning,
        )
        compare_functions(args, scipy_func, numba_func) 
開發者ID:numba,項目名稱:numba-scipy,代碼行數:23,代碼來源:test_special.py

示例12: df_slice

# 需要導入模塊: import scipy [as 別名]
# 或者: from scipy import special [as 別名]
def df_slice(df, elements, levels, drop_level=True, reset_index=False, return_none=False):
    if df is None:
        return None
    elements, levels = ensure_iterable(elements), ensure_iterable(levels)
    if not len(levels):
        return None
    if len(elements) != len(levels) and len(levels) > 1:
        raise ValueError('Number of elements ' + str(len(elements)) + ' must match the number of levels ' + str(len(levels)))

    # special case where we use a different method to handle multiple elements
    if len(levels) == 1 and len(elements) > 1:
        df =  df.reset_index().loc[df.reset_index()[levels[0]].isin(elements)].set_index(df.index.names)
    else:
        # remove levels if they are not in the df
        elements, levels = zip(*[(e, l) for e, l in zip(elements, levels) if l in df.index.names])
        result = df.xs(elements, level=levels, drop_level=drop_level)
        df = result.reset_index().set_index(result.index.names) if reset_index else result
    if not len(df) and return_none:
        return None
    else:
        return df 
開發者ID:energyPATHWAYS,項目名稱:EnergyPATHWAYS,代碼行數:23,代碼來源:util.py

示例13: gaussian_int

# 需要導入模塊: import scipy [as 別名]
# 或者: from scipy import special [as 別名]
def gaussian_int(n, alpha):
    r'''int_0^inf x^n exp(-alpha x^2) dx'''
    n1 = (n + 1) * .5
    return scipy.special.gamma(n1) / (2. * alpha**n1) 
開發者ID:pyscf,項目名稱:pyscf,代碼行數:6,代碼來源:mole.py

示例14: atom_symbol

# 需要導入模塊: import scipy [as 別名]
# 或者: from scipy import special [as 別名]
def atom_symbol(self, atm_id):
        r'''For the given atom id, return the input symbol (without striping special characters)

        Args:
            atm_id : int
                0-based

        Examples:

        >>> mol.build(atom='H^2 0 0 0; H 0 0 1.1')
        >>> mol.atom_symbol(0)
        H^2
        '''
        return _symbol(self._atom[atm_id][0]) 
開發者ID:pyscf,項目名稱:pyscf,代碼行數:16,代碼來源:mole.py

示例15: atom_pure_symbol

# 需要導入模塊: import scipy [as 別名]
# 或者: from scipy import special [as 別名]
def atom_pure_symbol(self, atm_id):
        r'''For the given atom id, return the standard symbol (striping special characters)

        Args:
            atm_id : int
                0-based

        Examples:

        >>> mol.build(atom='H^2 0 0 0; H 0 0 1.1')
        >>> mol.atom_symbol(0)
        H
        '''
        return _std_symbol(self._atom[atm_id][0]) 
開發者ID:pyscf,項目名稱:pyscf,代碼行數:16,代碼來源:mole.py


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