• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python multicomplex.bicomplex函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中numdifftools.multicomplex.bicomplex函数的典型用法代码示例。如果您正苦于以下问题:Python bicomplex函数的具体用法?Python bicomplex怎么用?Python bicomplex使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: test_der_abs

 def test_der_abs():
     x = np.linspace(-0.98, 0.98, 5)
     h = 1e-8
     der1 = abs(bicomplex(x + h * 1j, 0)).imag1 / h
     np.testing.assert_allclose(der1, np.where(x < 0, -1, 1))
     der2 = abs(bicomplex(x + h * 1j, h)).imag12 / h**2
     np.testing.assert_allclose(der2, 0, atol=1e-6)
开发者ID:inonchiu,项目名称:numdifftools,代码行数:7,代码来源:test_multicomplex.py


示例2: test_der_log

 def test_der_log():
     x = np.linspace(0.001, 5, 6)
     h = 1e-15
     der1 = np.log(bicomplex(x + h * 1j, 0)).imag1 / h
     np.testing.assert_allclose(der1, 1./x)
     der2 = np.log(bicomplex(x + h * 1j, h)).imag12 / h**2
     np.testing.assert_allclose(der2, -1./x**2)
开发者ID:inonchiu,项目名称:numdifftools,代码行数:7,代码来源:test_multicomplex.py


示例3: test_division

 def test_division():
     z1 = bicomplex(1, 2)
     z2 = bicomplex(3, 4)
     z3 = z1 / z2
     z4 = z1 * (z2**-1)
     np.testing.assert_allclose(z3.z1, z4.z1)
     np.testing.assert_allclose(z3.z2, z4.z2)
开发者ID:inonchiu,项目名称:numdifftools,代码行数:7,代码来源:test_multicomplex.py


示例4: test_dot

 def test_dot():
     z1 = bicomplex(1, 2)
     z2 = bicomplex(3, 4)
     z3 = z1.dot(z2)
     z4 = z1 * z2
     np.testing.assert_array_equal(z3.z1, z4.z1)
     np.testing.assert_array_equal(z3.z2, z4.z2)
开发者ID:inonchiu,项目名称:numdifftools,代码行数:7,代码来源:test_multicomplex.py


示例5: test_arg_c

    def test_arg_c():
        z1 = bicomplex(np.linspace(0, np.pi, 5), 0)
        z2 = z1.arg_c()
        np.testing.assert_array_equal(z2, np.arctan2(z1.z2.real, z1.z1.real))

        z3 = bicomplex(0.1, np.linspace(0, np.pi, 5))
        z4 = z3.arg_c()
        np.testing.assert_allclose(z4.real, np.arctan2(z3.z2.real, z3.z1.real))
开发者ID:inonchiu,项目名称:numdifftools,代码行数:8,代码来源:test_multicomplex.py


示例6: test_der_cos

 def test_der_cos():
     x = np.linspace(-0.99, 0.99, 5)
     h = 1e-9
     der1 = np.cos(bicomplex(x + h * 1j, 0)).imag1 / h
     np.testing.assert_allclose(der1, - np.sin(x))
     h *= 100
     der2 = np.cos(bicomplex(x + h * 1j, h)).imag12 / h**2
     np.testing.assert_allclose(der2, -np.cos(x))
开发者ID:inonchiu,项目名称:numdifftools,代码行数:8,代码来源:test_multicomplex.py


示例7: test_sub

    def test_sub():
        shape = (3, 3)
        z0 = bicomplex(np.ones(shape), 2 * np.ones(shape))
        z1 = bicomplex(3 * np.ones(shape), 4 * np.ones(shape))
        z2 = z0 - z1

        np.testing.assert_array_equal(z2.z1, z0.z1 - z1.z1)
        np.testing.assert_array_equal(z2.z2, z0.z2 - z1.z2)
开发者ID:inonchiu,项目名称:numdifftools,代码行数:8,代码来源:test_multicomplex.py


示例8: test_shape

    def test_shape(self):
        shape = (3, 3)
        t = np.arange(9).reshape(shape)
        z = bicomplex(t, 2 * t)
        self.assertEqual(z.shape, shape)

        z = bicomplex(1, 2)
        self.assertEqual(z.shape, ())
开发者ID:inonchiu,项目名称:numdifftools,代码行数:8,代码来源:test_multicomplex.py


示例9: test_der_arctan

    def test_der_arctan():
        x = np.linspace(0, 2, 5)
        h = 1e-8
        der1 = np.arctan(bicomplex(x + h * 1j, 0)).imag1 / h
        np.testing.assert_allclose(der1, 1. / (1 + x**2))

        der2 = bicomplex(x+h*1j, h).arctan().imag12/h**2
        np.testing.assert_allclose(der2, -2*x/(1+x**2)**2)
开发者ID:inonchiu,项目名称:numdifftools,代码行数:8,代码来源:test_multicomplex.py


示例10: test_norm

    def test_norm(self):
        shape = (3, 3)
        t = np.arange(9).reshape(shape)
        z = bicomplex(t, 2 * t)
        np.testing.assert_array_equal(z.norm(), np.sqrt(5*t**2))

        z = bicomplex(1, 2)
        self.assertEqual(z.norm(), np.sqrt(5))
开发者ID:inonchiu,项目名称:numdifftools,代码行数:8,代码来源:test_multicomplex.py


示例11: test_gt

 def test_gt():
     shape = (3, 3)
     t = np.arange(9).reshape(shape)
     z = bicomplex(t, 2 * t)
     z2 = bicomplex(1, 2)
     val = z > z2
     truth = np.array([[False,  False,  True],
                       [ True,  True,  True],
                       [ True,  True,  True]], dtype=bool)
     np.testing.assert_array_equal(val, truth)
开发者ID:inonchiu,项目名称:numdifftools,代码行数:10,代码来源:test_multicomplex.py


示例12: test_der_arccosh

    def test_der_arccosh():
        x = np.linspace(1.2, 5, 5)
        h = 1e-8
        der1 = np.arccosh(bicomplex(x + h * 1j, 0)).imag1 / h
        np.testing.assert_allclose(der1, 1. / np.sqrt(x**2 - 1))

        h = (_default_base_step(x, scale=2.5) + 1) - 1
        der2 = np.arccosh(bicomplex(x + h * 1j, h)).imag12 / h**2
        true_der2 = -x / (x**2-1)**(3. / 2)
        np.testing.assert_allclose(der2, true_der2, atol=1e-5)
开发者ID:inonchiu,项目名称:numdifftools,代码行数:10,代码来源:test_multicomplex.py


示例13: test_der_arccos

    def test_der_arccos(self):
        x = np.linspace(-0.98, 0.98, 5)
        h = 1e-8
        der1 = np.arccos(bicomplex(x + h * 1j, 0)).imag1 / h
        np.testing.assert_allclose(der1, -1. / np.sqrt(1 - x**2))

        h = (_default_base_step(x, scale=2.5) + 1) - 1
        der2 = np.arccos(bicomplex(x + h * 1j, h)).imag12 / h**2
        true_der2 = -x / (1 - x**2)**(3. / 2)
        np.testing.assert_allclose(der2, true_der2, atol=1e-5)
开发者ID:kikocorreoso,项目名称:numdifftools,代码行数:10,代码来源:test_multicomplex.py


示例14: test_add

    def test_add():
        shape = (3, 3)
        z0 = bicomplex(np.ones(shape), 2 * np.ones(shape))
        z1 = bicomplex(3 * np.ones(shape), 4 * np.ones(shape))
        z2 = z0 + z1

        np.testing.assert_array_equal(z2.z1, z0.z1 + z1.z1)
        np.testing.assert_array_equal(z2.z2, z0.z2 + z1.z2)
        z3 = z0 + 1
        np.testing.assert_array_equal(z3.z1, z0.z1 + 1)
        np.testing.assert_array_equal(z3.z2, z0.z2)
开发者ID:inonchiu,项目名称:numdifftools,代码行数:11,代码来源:test_multicomplex.py


示例15: test_pow

    def test_pow():
        z1 = bicomplex(1, 2)
        z2 = z1 ** 2
        z3 = z1 * z1
        np.testing.assert_allclose(z2.z1, z1.z1 * z1.z1 - z1.z2 * z1.z2)
        np.testing.assert_allclose(z2.z2, z1.z1 * z1.z2 + z1.z2 * z1.z1)
        np.testing.assert_allclose(z3.z1, z1.z1 * z1.z1 - z1.z2 * z1.z2)
        np.testing.assert_allclose(z3.z2, z1.z1 * z1.z2 + z1.z2 * z1.z1)

        z1 = bicomplex(z1=(-1j), z2=(-1-0j))

        z2 = z1 * z1
        z3 = z1 ** 2
        np.testing.assert_allclose(z2.z1, z1.z1 * z1.z1 - z1.z2 * z1.z2)
        np.testing.assert_allclose(z2.z2, z1.z1 * z1.z2 + z1.z2 * z1.z1)
        np.testing.assert_allclose(z3.z1, z1.z1 * z1.z1 - z1.z2 * z1.z2)
        np.testing.assert_allclose(z3.z2, z1.z1 * z1.z2 + z1.z2 * z1.z1)
开发者ID:inonchiu,项目名称:numdifftools,代码行数:17,代码来源:test_multicomplex.py


示例16: _test_first_derivative

def _test_first_derivative(name):
    x = np.linspace(0.0001, 0.98, 5)
    h = _default_base_step(x, scale=2)
    f, df = get_function(name, n=1)

    der = f(bicomplex(x + h * 1j, 0)).imag1 / h
    der_true = df(x)
    np.testing.assert_allclose(der, der_true, err_msg=('{0!s}'.format(name)))
开发者ID:inonchiu,项目名称:numdifftools,代码行数:8,代码来源:test_multicomplex.py


示例17: _test_second_derivative

def _test_second_derivative(name):
    x = np.linspace(0.01, 0.98, 5)
    h = _default_base_step(x, scale=2.5)
    # h = 1e-8
    f, df = get_function(name, n=2)

    der = f(bicomplex(x + h * 1j, h)).imag12 / h**2
    der_true = df(x)
    np.testing.assert_allclose(der, der_true, err_msg=('{0!s}'.format(name)))
开发者ID:inonchiu,项目名称:numdifftools,代码行数:9,代码来源:test_multicomplex.py


示例18: test_assign

 def test_assign():
     shape = (3, 3)
     z = bicomplex(np.ones(shape), 2 * np.ones(shape))
     z0 = z[0]
     np.testing.assert_array_equal(z0.z1, z.z1[0])
     np.testing.assert_array_equal(z0.z2, z.z2[0])
     z1 = z[:]
     np.testing.assert_array_equal(z1.z1, z.z1[:])
     np.testing.assert_array_equal(z1.z2, z.z2[:])
开发者ID:inonchiu,项目名称:numdifftools,代码行数:9,代码来源:test_multicomplex.py


示例19: _multicomplex2

 def _multicomplex2(f, fx, x, h, *args, **kwargs):
     """Calculate Hessian with bicomplex-step derivative approximation"""
     n = len(x)
     ee = np.diag(h)
     hess = np.outer(h, h)
     for i in range(n):
         for j in range(i, n):
             zph = bicomplex(x + 1j * ee[i, :], ee[j, :])
             hess[i, j] = (f(zph, *args, **kwargs)).imag12 / hess[j, i]
             hess[j, i] = hess[i, j]
     return hess
开发者ID:psktam-spacex,项目名称:numdifftools,代码行数:11,代码来源:core.py


示例20: test_subsref

 def test_subsref(self):
     shape = (3, 3)
     t = np.arange(9).reshape(shape)
     z = bicomplex(t, 2 * t)
     z0 = z[0]
     np.testing.assert_array_equal(z0.z1, z.z1[0])
     np.testing.assert_array_equal(z0.z2, z.z2[0])
     z1 = z[:]
     np.testing.assert_array_equal(z1.z1, z.z1[:])
     np.testing.assert_array_equal(z1.z2, z.z2[:])
     z1 = z[1:3, 1:3]
     np.testing.assert_array_equal(z1.z1, z.z1[1:3, 1:3])
     np.testing.assert_array_equal(z1.z2, z.z2[1:3, 1:3])
开发者ID:kikocorreoso,项目名称:numdifftools,代码行数:13,代码来源:test_multicomplex.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python numeric.array函数代码示例发布时间:2022-05-27
下一篇:
Python numbers.distance函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap