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

Python numpy.copysign函数代码示例

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

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



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

示例1: symOrtho

	def symOrtho(self, a, b):
		""" Computes the radius, cosine, and sine for the
		orthogonal transformation.
		@param a x vector.
		@param b y vector.
		@return [c,s,r]. Cosine value, Sine value, and the radius.
		"""
		s = 0
		c = 0
		r = 0
		if not b:
			r = np.abs(a)
			c = np.copysign(1,0,a)
		elif not a:
			r = np.abs(b)
			s = np.copysign(1,0,b)
		elif np.abs(b) > np.abs(a):
			t = a / b
			s = np.copysign(1.0,b) / np.sqrt(1.0 + t**2)
			c = s * t
			r = b / s
		else:
			t = b / a
			c = np.copysign(1.0,a) / np.sqrt(1.0 + t**2)
			s = c * t
			r = a / c
		return [c,s,r]
开发者ID:Barleyman,项目名称:FreeCAD_sf_master,代码行数:27,代码来源:bem_lsqr_cl.py


示例2: test_cross_div

def test_cross_div(dtypea, dtypeb, dtypec):
    if dtypea == np.int8 and dtypeb == np.int8:
        pytest.skip("Different behaviour in c++ and python for int8 / int8".format(dtypea, dtypeb))

    def fkt(a, b, c):
        c[:] = a / b

    hfkt = hope.jit(fkt)
    (ao, ah), (bo, bh), (co, ch) = random(dtypea, [10]), random(dtypeb, [10]), random(dtypec, [10])
    ao, ah, bo, bh = ao.astype(np.float64), ah.astype(np.float64), bo.astype(np.float64), bh.astype(np.float64)
    ao, ah = (
        np.copysign(np.power(np.abs(ao), 1.0 / 4.0), ao).astype(dtypea),
        np.copysign(np.power(np.abs(ah), 1.0 / 4.0), ah).astype(dtypea),
    )
    bo, bh = (
        np.copysign(np.power(np.abs(bo), 1.0 / 4.0), bo).astype(dtypeb),
        np.copysign(np.power(np.abs(bh), 1.0 / 4.0), bh).astype(dtypeb),
    )
    if np.count_nonzero(bo == 0) > 0:
        bo[bo == 0] += 1
    if np.count_nonzero(bh == 0) > 0:
        bh[bh == 0] += 1
    fkt(ao, bo, co), hfkt(ah, bh, ch)
    assert check(co, ch)
    fkt(ao, bo, co), hfkt(ah, bh, ch)
    assert check(co, ch)
开发者ID:you13,项目名称:hope,代码行数:26,代码来源:test_op_div.py


示例3: test_copysign

def test_copysign():
    assert_(np.copysign(1, -1) == -1)
    with np.errstate(divide="ignore"):
        assert_(1 / np.copysign(0, -1) < 0)
        assert_(1 / np.copysign(0, 1) > 0)
    assert_(np.signbit(np.copysign(np.nan, -1)))
    assert_(not np.signbit(np.copysign(np.nan, 1)))
开发者ID:Fematich,项目名称:article_browser,代码行数:7,代码来源:test_umath.py


示例4: test_signbit

    def test_signbit(self):
        from numpy import signbit, add, copysign, nan

        assert signbit(add.identity) == False
        assert (signbit([0, 0.0, 1, 1.0, float("inf")]) == [False, False, False, False, False]).all()
        assert (signbit([-0, -0.0, -1, -1.0, float("-inf")]) == [False, True, True, True, True]).all()
        assert (signbit([copysign(nan, 1), copysign(nan, -1)]) == [False, True]).all()
开发者ID:Qointum,项目名称:pypy,代码行数:7,代码来源:test_ufuncs.py


示例5: __step

    def __step(self, t, y, dt, control):
        u_v, u_s = control(t, y)
        v_x, v_y, r, s_f, x, y, o = y

        a_f = (v_y + self.L_f * r) / (v_x + 0.00001) - s_f
        a_r = (v_y - self.L_r * r) / (v_x + 0.00001)

        F_yf = -self.C_af * a_f
        F_yr = -self.C_ar * a_r

        n_v = self.noise_v(t) if self.noise_v else 0
        n_s = self.noise_s(t) if self.noise_s else 0

        u_s = u_s if abs(u_s) < self.max_u_s else np.copysign(self.max_u_s, u_s)
        u_v = u_v if abs(u_v) < self.max_u_v else np.copysign(self.max_u_v, u_v)

        if abs(s_f + u_s * dt) > self.max_s:
            u_s = np.copysign(self.max_s - 0.05, s_f) - s_f

        self._uv = u_v
        self._us = u_s

        F_res = self.F_res() * v_x

        d_v_x = (-F_yf * np.sin(s_f) + u_v - F_res * np.cos(s_f) - F_res + n_v) / self.m + v_y * r
        d_v_y = (F_yf * np.cos(s_f) + F_yr - F_res * np.sin(s_f)) / self.m - v_x * r
        d_r = self.L_f * (F_yf * np.cos(s_f) - F_res * np.sin(s_f)) / self.I_z - self.L_r * F_yr / self.I_z + n_s
        d_s = u_s
        d_x = v_x * np.cos(o) - v_y * np.sin(o)
        d_y = v_x * np.sin(o) + v_y * np.cos(o)
        d_o = r

        return [d_v_x, d_v_y, d_r, d_s, d_x, d_y, d_o]
开发者ID:alexeyden,项目名称:Robot-Stuff,代码行数:33,代码来源:model.py


示例6: test_copysign_array

    def test_copysign_array(self):
        assert np.all(np.copysign(np.array([1., 2., 3.]) * u.s, -1.) == -np.array([1., 2., 3.]) * u.s)
        assert np.all(np.copysign(np.array([1., 2., 3.]) * u.s, -1. * u.m) == -np.array([1., 2., 3.]) * u.s)
        assert np.all(np.copysign(np.array([1., 2., 3.]) * u.s, np.array([-2.,2.,-4.]) * u.m) == np.array([-1., 2., -3.]) * u.s)

        q = np.copysign(np.array([1., 2., 3.]), -3 * u.m)
        assert np.all(q == np.array([-1., -2., -3.]))
        assert not isinstance(q, u.Quantity)
开发者ID:n0d,项目名称:astropy,代码行数:8,代码来源:test_quantity_ufuncs.py


示例7: calibrate

    def calibrate(self, steps): # calibration values in uW
        rng = np.arange(0,steps)
        x = np.zeros(steps,dtype = float)
        y = np.zeros(steps,dtype = float)
        
        self.set_power(0)
        self._ins_pm.set_wavelength(self._wavelength)
        time.sleep(2)
        bg = self._ins_pm.get_power()

        print 'background power: %.4f uW' % (bg*1e6)

        time.sleep(.2)

        V_max = self.get_V_max()
        V_min = self.get_V_min()
        
        if V_max + V_min < 0: rng=np.flipud(rng)
        
        for a in rng:
            x[a] = a*(V_max-V_min)/float(steps-1)+V_min
            self.apply_voltage(x[a])
            time.sleep(0.5)
            y[a] = self._ins_pm.get_power() - bg
            
            print 'measured power at %.2f V: %.4f uW' % \
                    (x[a], y[a]*1e6)
        
        #x= x*(V_max-V_min)/float(steps-1)+V_min 
        a, xc, k = np.copysign(np.max(y), V_max + V_min), np.copysign(.1, V_max + V_min), np.copysign(5., V_max + V_min)
        fitres = fit.fit1d(x,y, common.fit_AOM_powerdependence, 
                a, xc, k, do_print=True, ret=True)
     
        fd = np.zeros(len(x))        
        if type(fitres) != type(False):
            p1 = fitres['params_dict']
            self.set_cal_a(p1['a'])
            self.set_cal_xc(p1['xc'])
            self.set_cal_k(p1['k'])
            fd = fitres['fitfunc'](x)
        else:
            print 'could not fit calibration curve!'
        
        dat = qt.Data(name= 'aom_calibration_'+self._name+'_'+\
                self._cur_controller)
        dat.add_coordinate('Voltage [V]')
        dat.add_value('Power [W]')
        dat.add_value('fit')
        dat.create_file()
        plt = qt.Plot2D(dat, 'rO', name='aom calibration', coorddim=0, valdim=1, 
                clear=True)
        plt.add_data(dat, coorddim=0, valdim=2)
        dat.add_data_point(x,y,fd)
        dat.close_file()
        plt.save_png(dat.get_filepath()+'png')

        self.save_cfg()
        print (self._name+' calibration finished')
开发者ID:AdriaanRol,项目名称:measurement,代码行数:58,代码来源:AOM.py


示例8: test_binary_pow

def test_binary_pow(dtype, shape):
    def fkt(a, c):
        c[:] = a ** 2
    hfkt = hope.jit(fkt)
    (ao, ah), (co, ch) = random(dtype, shape), random(dtype, shape)
    ao, ah = np.copysign(np.sqrt(np.abs(ao)), ao).astype(dtype), np.copysign(np.sqrt(np.abs(ah)), ah).astype(dtype)
    fkt(ao, co),  hfkt(ah, ch)
    assert check(co, ch)
    fkt(ao, co),  hfkt(ah, ch)
    assert check(co, ch)
开发者ID:BrainGrylls,项目名称:hope,代码行数:10,代码来源:test_op_pow.py


示例9: test_copysign

def test_copysign():
    assert_(np.copysign(1, -1) == -1)
    old_err = np.seterr(divide="ignore")
    try:
        assert_(1 / np.copysign(0, -1) < 0)
        assert_(1 / np.copysign(0, 1) > 0)
    finally:
        np.seterr(**old_err)
    assert_(np.signbit(np.copysign(np.nan, -1)))
    assert_(not np.signbit(np.copysign(np.nan, 1)))
开发者ID:jarrodmillman,项目名称:numpy,代码行数:10,代码来源:test_umath.py


示例10: test_augmented_mult

def test_augmented_mult(dtype, shape):
    def fkt(a, c):
        c[:] *= a
    hfkt = hope.jit(fkt)
    (ao, ah), (co, ch) = random(dtype, shape), random(dtype, shape)
    ao, ah = np.copysign(np.power(np.abs(ao), 1. / 4.), ao).astype(dtype), np.copysign(np.power(np.abs(ah), 1. / 4.), ah).astype(dtype)
    co, ch = np.copysign(np.power(np.abs(co), 1. / 4.), co).astype(dtype), np.copysign(np.power(np.abs(ch), 1. / 4.), ch).astype(dtype)
    ro, rh = fkt(ao, co),  hfkt(ah, ch)
    assert check(co, ch)
    ro, rh = fkt(ao, co),  hfkt(ah, ch)
    assert check(co, ch)
开发者ID:BrainGrylls,项目名称:hope,代码行数:11,代码来源:test_op_mult.py


示例11: adjustDxn

def adjustDxn(dx1,dx2,rcore,tol=1e-10):
    r = np.sqrt(dx1**2 + dx2**2)     
    if (r**2 < rcore**2*tol):
        rcorefac = rcore/np.sqrt(2.0)
        dx1 = np.copysign(rcorefac,dx1)
        dx2 = np.copysign(rcorefac,dx2)
    elif (r**2 < rcore**2):
        rfac = rcore/r
        dx1 = dx1*rfac
        dx2 = dx2*rfac
    return dx1, dx2
开发者ID:varunprajan,项目名称:PythonModules,代码行数:11,代码来源:dislfields.py


示例12: test_opt_pow_array

def test_opt_pow_array(dtype, shape):
    def fkt(a, c):
        c[:] = a ** 2.0 + a ** 4 + a ** 7
    hope.config.optimize = True
    hfkt = hope.jit(fkt)
    (ao, ah), (co, ch) = random(dtype, shape), random(dtype, shape)
    ao, ah = np.copysign(np.power(np.abs(ao), 1. / 8.), ao).astype(dtype), np.copysign(np.power(np.abs(ah), 1. / 8.), ah).astype(dtype)
    fkt(ao, co),  hfkt(ah, ch)
    assert check(co, ch)
    fkt(ao, co),  hfkt(ah, ch)
    assert check(co, ch)
    hope.config.optimize = False
开发者ID:BrainGrylls,项目名称:hope,代码行数:12,代码来源:test_optimize.py


示例13: dms2deg

def dms2deg(char):
    
    """
    Function used to transform the Declination from the fits file given in degrees, minutes and seconds
    to degrees.
    Argument: The dec as a string of characters
    output: A float number: the Dec written in degrees
    """
    d,m,s = [float(x) for x in char.split()]
    m,s = np.copysign(m,d),np.copysign(s,d) # The arcminutes and arcseconds adquire the same sign of degrees to be added later
    out = (d + m/60.+ s/3600.) 
    return out
开发者ID:deprecated,项目名称:proplyd-slits,代码行数:12,代码来源:proplyds.py


示例14: test_opt_pow_scalar

def test_opt_pow_scalar(dtype):
    def fkt(a, c):
        c[0] = a ** 2 + a ** 4 + a ** 7.0
    hope.config.optimize = True
    hfkt = hope.jit(fkt)
    (ao, ah), (co, ch) = random(dtype, []), random(dtype, [1])
    ao, ah = np.copysign(np.power(np.abs(ao), 1. / 8.), ao).astype(dtype), np.copysign(np.power(np.abs(ah), 1. / 8.), ah).astype(dtype)
    fkt(ao, co),  hfkt(ah, ch)
    assert check(co, ch)
    fkt(ao, co),  hfkt(ah, ch)
    assert check(co, ch)
    hope.config.optimize = False
开发者ID:BrainGrylls,项目名称:hope,代码行数:12,代码来源:test_optimize.py


示例15: test_return_arr_expr

def test_return_arr_expr(dtype, shape):
    def fkt(a, c):
        return a ** -2 + a ** -4.0 + a ** -7
    hfkt = hope.jit(fkt)
    (ao, ah), (co, ch) = random(dtype, shape), random(dtype, shape)
    ao, ah = np.copysign(np.power(np.abs(ao), 1. / 8.), ao).astype(dtype), np.copysign(np.power(np.abs(ah), 1. / 8.), ah).astype(dtype)
    if np.count_nonzero(ao == 0) > 0: ao[ao == 0] += 1
    if np.count_nonzero(ah == 0) > 0: ah[ah == 0] += 1
    fkt(ao, co),  hfkt(ah, ch)
    assert check(co, ch)
    fkt(ao, co),  hfkt(ah, ch)
    assert check(co, ch)
开发者ID:BrainGrylls,项目名称:hope,代码行数:12,代码来源:test_return.py


示例16: test_binary_mult

def test_binary_mult(dtype, shape):
    def fkt(a, b, c):
        c[:] = a * b
    hfkt = hope.jit(fkt)
    (ao, ah), (bo, bh), (co, ch) = random(dtype, shape), random(dtype, shape), random(dtype, shape)
    ao = np.copysign(np.sqrt(np.abs(ao.astype(np.float64))).astype(dtype), ao).astype(dtype)
    ah = np.copysign(np.sqrt(np.abs(ah.astype(np.float64))).astype(dtype), ah).astype(dtype)
    bo = np.copysign(np.sqrt(np.abs(bo.astype(np.float64))).astype(dtype), bo).astype(dtype)
    bh = np.copysign(np.sqrt(np.abs(bh.astype(np.float64))).astype(dtype), bh).astype(dtype)
    ro, rh = fkt(ao, bo, co),  hfkt(ah, bh, ch)
    assert check(co, ch)
    ro, rh = fkt(ao, bo, co),  hfkt(ah, bh, ch)
    assert check(co, ch)
开发者ID:BrainGrylls,项目名称:hope,代码行数:13,代码来源:test_op_mult.py


示例17: test_augmented_pow

def test_augmented_pow(dtype, shape):
    def fkt(a, c): 
        c[:] **= a
    hfkt = hope.jit(fkt)
    (ao, ah), (co, ch) = random(np.uint8, shape), random(dtype, shape)
    if np.count_nonzero(ao == 0) > 0: ao[ao == 0] += 1
    if np.count_nonzero(ah == 0) > 0: ah[ah == 0] += 1
    if np.count_nonzero(co == 0) > 0: co[co == 0] += 1
    if np.count_nonzero(ch == 0) > 0: ch[ch == 0] += 1
    co, ch = np.copysign(np.sqrt(np.abs(co)), co).astype(dtype), np.copysign(np.sqrt(np.abs(ch)), ch).astype(dtype)
    ao, ah = np.power(np.abs(ao).astype(np.float64), 1. / co.astype(np.float64)).astype(dtype), np.power(np.abs(ah).astype(np.float64), 1. / ch.astype(np.float64)).astype(dtype)
    fkt(ao, co),  hfkt(ah, ch)
    assert check(co, ch)
开发者ID:BrainGrylls,项目名称:hope,代码行数:13,代码来源:test_op_pow.py


示例18: test_copysign

    def test_copysign(self):
        from numpy import array, copysign

        reference = [5.0, -0.0, 0.0, -6.0]
        a = array([-5.0, 0.0, 0.0, 6.0])
        b = array([5.0, -0.0, 3.0, -6.0])
        c = copysign(a, b)
        for i in range(4):
            assert c[i] == reference[i]

        b = array([True, True, True, True], dtype=bool)
        c = copysign(a, b)
        for i in range(4):
            assert c[i] == abs(a[i])
开发者ID:Qointum,项目名称:pypy,代码行数:14,代码来源:test_ufuncs.py


示例19: test_opt_neg_pow_array

def test_opt_neg_pow_array(dtype, shape):
    def fkt(a, c):
        c[:] = a ** -2 + a ** -4.0 + a ** -7
    hope.config.optimize = True
    hfkt = hope.jit(fkt)
    (ao, ah), (co, ch) = random(dtype, shape), random(dtype, shape)
    ao, ah = np.copysign(np.power(np.abs(ao), 1. / 8.), ao).astype(dtype), np.copysign(np.power(np.abs(ah), 1. / 8.), ah).astype(dtype)
    if np.count_nonzero(ao == 0) > 0: ao[ao == 0] += 1
    if np.count_nonzero(ah == 0) > 0: ah[ah == 0] += 1
    fkt(ao, co),  hfkt(ah, ch)
    assert check(co, ch)
    fkt(ao, co),  hfkt(ah, ch)
    assert check(co, ch)
    hope.config.optimize = False
开发者ID:BrainGrylls,项目名称:hope,代码行数:14,代码来源:test_optimize.py


示例20: test_opt_basic_scalar

def test_opt_basic_scalar(dtype):
    def fkt(a, c):
        c[0] = (a + a) * a - 1 / a
    hope.config.optimize = True
    hfkt = hope.jit(fkt)
    (ao, ah), (co, ch) = random(dtype, []), random(dtype, [1])
    ao, ah = np.copysign(np.power(np.abs(ao), 1. / 4.), ao).astype(dtype), np.copysign(np.power(np.abs(ah), 1. / 4.), ah).astype(dtype)
    if np.count_nonzero(ao == 0) > 0: ao[ao == 0] += 1
    if np.count_nonzero(ah == 0) > 0: ah[ah == 0] += 1
    fkt(ao, co),  hfkt(ah, ch)
    assert check(co, ch)
    fkt(ao, co),  hfkt(ah, ch)
    assert check(co, ch)
    hope.config.optimize = False
开发者ID:BrainGrylls,项目名称:hope,代码行数:14,代码来源:test_optimize.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python numpy.copyto函数代码示例发布时间:2022-05-27
下一篇:
Python numpy.copy函数代码示例发布时间: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