当前位置: 首页>>代码示例>>Python>>正文


Python umath.exp方法代码示例

本文整理汇总了Python中numpy.core.umath.exp方法的典型用法代码示例。如果您正苦于以下问题:Python umath.exp方法的具体用法?Python umath.exp怎么用?Python umath.exp使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在numpy.core.umath的用法示例。


在下文中一共展示了umath.exp方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_power_float

# 需要导入模块: from numpy.core import umath [as 别名]
# 或者: from numpy.core.umath import exp [as 别名]
def test_power_float(self):
        x = np.array([1., 2., 3.])
        assert_equal(x**0, [1., 1., 1.])
        assert_equal(x**1, x)
        assert_equal(x**2, [1., 4., 9.])
        y = x.copy()
        y **= 2
        assert_equal(y, [1., 4., 9.])
        assert_almost_equal(x**(-1), [1., 0.5, 1./3])
        assert_almost_equal(x**(0.5), [1., ncu.sqrt(2), ncu.sqrt(3)])

        for out, inp, msg in _gen_alignment_data(dtype=np.float32,
                                                 type='unary'):
            exp = [ncu.sqrt(i) for i in inp]
            assert_almost_equal(inp**(0.5), exp, err_msg=msg)
            np.sqrt(inp, out=out)
            assert_equal(out, exp, err_msg=msg)

        for out, inp, msg in _gen_alignment_data(dtype=np.float64,
                                                 type='unary'):
            exp = [ncu.sqrt(i) for i in inp]
            assert_almost_equal(inp**(0.5), exp, err_msg=msg)
            np.sqrt(inp, out=out)
            assert_equal(out, exp, err_msg=msg) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:26,代码来源:test_umath.py

示例2: test_power_float

# 需要导入模块: from numpy.core import umath [as 别名]
# 或者: from numpy.core.umath import exp [as 别名]
def test_power_float(self):
        x = np.array([1., 2., 3.])
        assert_equal(x**0, [1., 1., 1.])
        assert_equal(x**1, x)
        assert_equal(x**2, [1., 4., 9.])
        y = x.copy()
        y **= 2
        assert_equal(y, [1., 4., 9.])
        assert_almost_equal(x**(-1), [1., 0.5, 1./3])
        assert_almost_equal(x**(0.5), [1., ncu.sqrt(2), ncu.sqrt(3)])

        for out, inp, msg in _gen_alignment_data(dtype=np.float32,
                                                 type='unary',
                                                 max_size=11):
            exp = [ncu.sqrt(i) for i in inp]
            assert_almost_equal(inp**(0.5), exp, err_msg=msg)
            np.sqrt(inp, out=out)
            assert_equal(out, exp, err_msg=msg)

        for out, inp, msg in _gen_alignment_data(dtype=np.float64,
                                                 type='unary',
                                                 max_size=7):
            exp = [ncu.sqrt(i) for i in inp]
            assert_almost_equal(inp**(0.5), exp, err_msg=msg)
            np.sqrt(inp, out=out)
            assert_equal(out, exp, err_msg=msg) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:28,代码来源:test_umath.py

示例3: test_exp_values

# 需要导入模块: from numpy.core import umath [as 别名]
# 或者: from numpy.core.umath import exp [as 别名]
def test_exp_values(self):
        x = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]
        y = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
        for dt in ['f', 'd', 'g']:
            log2_ = 0.69314718055994530943
            xf = np.array(x, dtype=dt)
            yf = np.array(y, dtype=dt)*log2_
            assert_almost_equal(np.exp(yf), xf) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:10,代码来源:test_umath.py

示例4: test_expm1

# 需要导入模块: from numpy.core import umath [as 别名]
# 或者: from numpy.core.umath import exp [as 别名]
def test_expm1(self):
        assert_almost_equal(ncu.expm1(0.2), ncu.exp(0.2)-1)
        assert_almost_equal(ncu.expm1(1e-6), ncu.exp(1e-6)-1) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:5,代码来源:test_umath.py

示例5: test_exp_values

# 需要导入模块: from numpy.core import umath [as 别名]
# 或者: from numpy.core.umath import exp [as 别名]
def test_exp_values(self) :
        x = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]
        y = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
        for dt in ['f', 'd', 'g'] :
            log2_ = 0.69314718055994530943
            xf = np.array(x, dtype=dt)
            yf = np.array(y, dtype=dt)*log2_
            assert_almost_equal(np.exp(yf), xf) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:10,代码来源:test_umath.py

示例6: test_priority

# 需要导入模块: from numpy.core import umath [as 别名]
# 或者: from numpy.core.umath import exp [as 别名]
def test_priority(self):
        class A(object):
            def __array__(self):
                return np.zeros(1)
            def __array_wrap__(self, arr, context):
                r = type(self)()
                r.arr = arr
                r.context = context
                return r
        class B(A):
            __array_priority__ = 20.
        class C(A):
            __array_priority__ = 40.
        x = np.zeros(1)
        a = A()
        b = B()
        c = C()
        f = ncu.minimum
        self.assertTrue(type(f(x, x)) is np.ndarray)
        self.assertTrue(type(f(x, a)) is A)
        self.assertTrue(type(f(x, b)) is B)
        self.assertTrue(type(f(x, c)) is C)
        self.assertTrue(type(f(a, x)) is A)
        self.assertTrue(type(f(b, x)) is B)
        self.assertTrue(type(f(c, x)) is C)

        self.assertTrue(type(f(a, a)) is A)
        self.assertTrue(type(f(a, b)) is B)
        self.assertTrue(type(f(b, a)) is B)
        self.assertTrue(type(f(b, b)) is B)
        self.assertTrue(type(f(b, c)) is C)
        self.assertTrue(type(f(c, b)) is C)
        self.assertTrue(type(f(c, c)) is C)

        self.assertTrue(type(ncu.exp(a) is A))
        self.assertTrue(type(ncu.exp(b) is B))
        self.assertTrue(type(ncu.exp(c) is C)) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:39,代码来源:test_umath.py


注:本文中的numpy.core.umath.exp方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。