本文整理汇总了Python中scipy.special.cbrt方法的典型用法代码示例。如果您正苦于以下问题:Python special.cbrt方法的具体用法?Python special.cbrt怎么用?Python special.cbrt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scipy.special
的用法示例。
在下文中一共展示了special.cbrt方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_scipy_special_helpers
# 需要导入模块: from scipy import special [as 别名]
# 或者: from scipy.special import cbrt [as 别名]
def get_scipy_special_helpers():
import scipy.special as sps
SCIPY_HELPERS = {}
for name in dimensionless_to_dimensionless_sps_ufuncs:
# TODO: Revert https://github.com/astropy/astropy/pull/7219 when
# astropy requires scipy>=0.18, and loggamma is guaranteed
# to exist.
# See https://github.com/astropy/astropy/issues/7159
ufunc = getattr(sps, name, None)
if ufunc:
SCIPY_HELPERS[ufunc] = helper_dimensionless_to_dimensionless
for ufunc in degree_to_dimensionless_sps_ufuncs:
SCIPY_HELPERS[getattr(sps, ufunc)] = helper_degree_to_dimensionless
for ufunc in two_arg_dimensionless_sps_ufuncs:
SCIPY_HELPERS[getattr(sps, ufunc)] = helper_two_arg_dimensionless
# ufuncs handled as special cases
SCIPY_HELPERS[sps.cbrt] = helper_cbrt
SCIPY_HELPERS[sps.radian] = helper_degree_minute_second_to_radian
return SCIPY_HELPERS
示例2: test_cbrt
# 需要导入模块: from scipy import special [as 别名]
# 或者: from scipy.special import cbrt [as 别名]
def test_cbrt(self):
assert_approx_equal(cephes.cbrt(1),1.0)
示例3: test_cbrtmore
# 需要导入模块: from scipy import special [as 别名]
# 或者: from scipy.special import cbrt [as 别名]
def test_cbrtmore(self):
cb1 = special.cbrt(27.9)
cbrl1 = 27.9**(1.0/3.0)
assert_almost_equal(cb1,cbrl1,8)
示例4: scott
# 需要导入模块: from scipy import special [as 别名]
# 或者: from scipy.special import cbrt [as 别名]
def scott(data, ddof=0):
"""
Scott's rule for the number of bins in a histogram.
"""
if np.std(data, ddof=ddof) == 0:
return sturges_rule(data)
h = 3.5*np.std(data, ddof=ddof)/cbrt(len(data))
return int((np.max(data) - np.min(data))/h)
示例5: test_cbrt_array
# 需要导入模块: from scipy import special [as 别名]
# 或者: from scipy.special import cbrt [as 别名]
def test_cbrt_array(self, function):
# Calculate cbrt on both sides since on Windows the cube root of 64
# does not exactly equal 4. See 4388.
values = np.array([1., 8., 64.])
assert np.all(function(values * u.m**3) ==
function(values) * u.m)
示例6: _distort_tsai
# 需要导入模块: from scipy import special [as 别名]
# 或者: from scipy.special import cbrt [as 别名]
def _distort_tsai(self, metric_image_coord):
"""
Distort centered metric image coordinates following Tsai model.
See: Devernay, Frederic, and Olivier Faugeras. "Straight lines have to be straight."
Machine vision and applications 13.1 (2001): 14-24. Section 2.1.
(only for illustration, the formulas didn't work for me)
http://www.cvg.rdg.ac.uk/PETS2009/sample.zip :CameraModel.cpp:CameraModel::undistortedToDistortedSensorCoord
Analytical inverse of the undistort_tsai() function.
:param metric_image_coord: centered metric image coordinates
(metric image coordinate = image_xy * f / z)
:type metric_image_coord: numpy.ndarray, shape=(2, n)
:return: distorted centered metric image coordinates
:rtype: numpy.ndarray, shape=(2, n)
"""
assert metric_image_coord.shape[0] == 2
x = metric_image_coord[0, :] # vector
y = metric_image_coord[1, :] # vector
r_u = np.sqrt(x ** 2 + y ** 2) # vector
c = 1.0 / self.tsai_kappa # scalar
d = -c * r_u # vector
# solve polynomial of 3rd degree for r_distorted using Cardan method:
# https://proofwiki.org/wiki/Cardano%27s_Formula
# r_distorted ** 3 + c * r_distorted + d = 0
q = c / 3. # scalar
r = -d / 2. # vector
delta = q ** 3 + r ** 2 # polynomial discriminant, vector
positive_mask = delta >= 0
r_distorted = np.zeros((metric_image_coord.shape[1]))
# discriminant > 0
s = cbrt(r[positive_mask] + np.sqrt(delta[positive_mask]))
t = cbrt(r[positive_mask] - np.sqrt(delta[positive_mask]))
r_distorted[positive_mask] = s + t
# discriminant < 0
delta_sqrt = np.sqrt(-delta[~positive_mask])
s = cbrt(np.sqrt(r[~positive_mask] ** 2 + delta_sqrt ** 2))
# s = cbrt(np.sqrt(r[~positive_mask] ** 2 + (-delta[~positive_mask]) ** 2))
t = 1. / 3 * np.arctan2(delta_sqrt, r[~positive_mask])
r_distorted[~positive_mask] = -s * np.cos(t) + s * np.sqrt(3) * np.sin(t)
return metric_image_coord * r_distorted / r_u