本文整理汇总了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)
示例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
示例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
示例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
示例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
示例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
)
示例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
)
示例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)
示例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
示例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
示例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)
示例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
示例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)
示例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])
示例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])