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


Python numpy.copysign方法代码示例

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


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

示例1: test_cross_div

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import copysign [as 别名]
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. / 4.), ao).astype(dtypea), np.copysign(np.power(np.abs(ah), 1. / 4.), ah).astype(dtypea)
    bo, bh = np.copysign(np.power(np.abs(bo), 1. / 4.), bo).astype(dtypeb), np.copysign(np.power(np.abs(bh), 1. / 4.), 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:jakeret,项目名称:hope,代码行数:18,代码来源:test_op_div.py

示例2: __init__

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import copysign [as 别名]
def __init__(
        self,
        asset,
        quantity,
        dt,
        price,
        order_id,
        commission=0.0
    ):
        self.asset = asset
        self.quantity = quantity
        self.direction = np.copysign(1, self.quantity)
        self.dt = dt
        self.price = price
        self.order_id = order_id
        self.commission = commission 
开发者ID:mhallsmoore,项目名称:qstrader,代码行数:18,代码来源:transaction.py

示例3: to_geodetic

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import copysign [as 别名]
def to_geodetic(z_coord, hypot_xy):
        """ Get geodetic coordinates calculated by the Ferrarri's solution. """
        ee4 = WGS84_EPS2**2
        pa2 = (hypot_xy / WGS84_A)**2
        zt = (1.0 - WGS84_EPS2) * (z_coord / WGS84_A)**2
        rh = (pa2 + zt - ee4)/6.0
        ss = (0.25*ee4) * zt * pa2
        rh3 = rh**3
        tmp = rh3 + ss + sqrt(ss*(ss+2.0*rh3))
        tt = copysign(fabs(tmp)**(1.0/3.0), tmp)
        uu = rh + tt + rh**2 / tt
        vv = sqrt(uu**2 + ee4*zt)
        ww = (0.5*WGS84_EPS2) * (uu + vv - zt)/vv
        kp = 1.0 + WGS84_EPS2*(sqrt(uu + vv + ww**2) + ww)/(uu + vv)
        zkp = kp * z_coord
        return (
            RAD2DEG*arctan2(zkp, hypot_xy),
            hypot(hypot_xy, zkp)*(1.0/kp - 1.0 + WGS84_EPS2)/WGS84_EPS2
        ) 
开发者ID:igp-gravity,项目名称:geoist,代码行数:21,代码来源:pymm_convert.py

示例4: custom_line

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import copysign [as 别名]
def custom_line(
        self, name: str, data: np.ndarray, offset: bool, invert: bool = True
    ):
        """
        :param offset:
        - True, for untriggered wave data:
            - line will be shifted and triggered (by offset_viewport()).
        - False, for triggered data and buffers:
            - line is immune to offset_viewport().

        :param invert:
        - True, for wave (data and buffers):
            - If wave data is inverted (edge_direction = -1),
              data will be plotted inverted.
        - False, for buffers and autocorrelated wave data:
            - Data is plotted as-is.
        """
        if self._renderer is None:
            return
        data = data / abs_max(data, 0.01) / 2
        if invert:
            data *= np.copysign(1, self._wave.amplification)
        self._renderer.update_custom_line(
            name, self._wave_idx, self._stride, data, offset=offset
        ) 
开发者ID:corrscope,项目名称:corrscope,代码行数:27,代码来源:triggers.py

示例5: dms_to_degrees

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import copysign [as 别名]
def dms_to_degrees(d, m, s=None):
    """
    Convert degrees, arcminute, arcsecond to a float degrees value.
    """

    _check_minute_range(m)
    _check_second_range(s)

    # determine sign
    sign = np.copysign(1.0, d)

    try:
        d = np.floor(np.abs(d))
        if s is None:
            m = np.abs(m)
            s = 0
        else:
            m = np.floor(np.abs(m))
            s = np.abs(s)
    except ValueError:
        raise ValueError(format_exception(
            "{func}: dms values ({1[0]},{2[1]},{3[2]}) could not be "
            "converted to numbers.", d, m, s))

    return sign * (d + m / 60. + s / 3600.) 
开发者ID:holzschu,项目名称:Carnets,代码行数:27,代码来源:angle_utilities.py

示例6: hms_to_hours

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import copysign [as 别名]
def hms_to_hours(h, m, s=None):
    """
    Convert hour, minute, second to a float hour value.
    """

    check_hms_ranges(h, m, s)

    # determine sign
    sign = np.copysign(1.0, h)

    try:
        h = np.floor(np.abs(h))
        if s is None:
            m = np.abs(m)
            s = 0
        else:
            m = np.floor(np.abs(m))
            s = np.abs(s)
    except ValueError:
        raise ValueError(format_exception(
            "{func}: HMS values ({1[0]},{2[1]},{3[2]}) could not be "
            "converted to numbers.", h, m, s))

    return sign * (h + m / 60. + s / 3600.) 
开发者ID:holzschu,项目名称:Carnets,代码行数:26,代码来源:angle_utilities.py

示例7: idl_round

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import copysign [as 别名]
def idl_round(x):
    """
    Round to the *nearest* integer, half-away-from-zero.

    Parameters
    ----------
    x : array-like
        Number or array to be rounded

    Returns
    -------
    r_rounded : array-like
        note that the returned values are floats

    Notes
    -----
    IDL ``ROUND`` rounds to the *nearest* integer (commercial rounding),
    unlike numpy's round/rint, which round to the nearest *even*
    value (half-to-even, financial rounding) as defined in IEEE-754
    standard.

    """
    return np.trunc(x + np.copysign(0.5, x)) 
开发者ID:vortex-exoplanet,项目名称:VIP,代码行数:25,代码来源:utils.py

示例8: __call__

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import copysign [as 别名]
def __call__(self, array):
        if self.dtype is not None:
            assert array.dtype == self.dtype
        xp = cuda.get_array_module(array)
        if not array.shape:  # 0-dim case
            array[...] = self.scale * (2 * numpy.random.randint(2) - 1)
        elif not array.size:
            raise ValueError('Array to be initialized must be non-empty.')
        else:
            # numpy.prod returns float value when the argument is empty.
            out_dim = len(array)
            in_dim = size_of_shape(array.shape[1:])
            if (in_dim > out_dim and self._checks[0]) or (
                    in_dim < out_dim and self._checks[1]):
                raise ValueError(
                    'Cannot make orthogonal {}.'
                    'shape = {}, interpreted as '
                    '{}-dim input and {}-dim output.'.format(
                        self.mode, array.shape, in_dim, out_dim))
            transpose = in_dim > out_dim
            a = numpy.random.normal(size=(out_dim, in_dim))
            if transpose:
                a = a.T
            # cupy.linalg.qr requires cusolver in CUDA 8+
            q, r = numpy.linalg.qr(a)
            q *= numpy.copysign(self.scale, numpy.diag(r))
            if transpose:
                q = q.T
            array[...] = xp.asarray(q.reshape(array.shape)) 
开发者ID:chainer,项目名称:chainerrl,代码行数:31,代码来源:orthogonal.py

示例9: test_copysign

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import copysign [as 别名]
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:Frank-qlu,项目名称:recruit,代码行数:9,代码来源:test_umath.py

示例10: f32_copysign

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import copysign [as 别名]
def f32_copysign(config: Configuration, i: binary.Instruction):
        b = config.stack.pop().f32()
        a = config.stack.pop().f32()
        r = Value.from_f32(numpy.copysign(a, b))
        config.stack.append(r) 
开发者ID:mohanson,项目名称:pywasm,代码行数:7,代码来源:execution.py

示例11: f64_copysign

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import copysign [as 别名]
def f64_copysign(config: Configuration, i: binary.Instruction):
        b = config.stack.pop().f64()
        a = config.stack.pop().f64()
        r = Value.from_f64(numpy.copysign(a, b))
        config.stack.append(r) 
开发者ID:mohanson,项目名称:pywasm,代码行数:7,代码来源:execution.py

示例12: __call__

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import copysign [as 别名]
def __call__(self, array):
        if self.dtype is not None:
            assert array.dtype == self.dtype,\
                '{} != {}'.format(array.dtype, self.dtype)
        if not array.shape:  # 0-dim case
            if self.rng is None:
                a = numpy.random.randint(2)
            else:
                a = self.rng.randint(2)
            a = int(a)
            array[...] = self.scale * (2 * a - 1)
        elif not array.size:
            raise ValueError('Array to be initialized must be non-empty.')
        else:
            # numpy.prod returns float value when the argument is empty.
            out_dim = len(array)
            in_dim = utils.size_of_shape(array.shape[1:])
            if (in_dim > out_dim and self._checks[0]) or (
                    in_dim < out_dim and self._checks[1]):
                raise ValueError(
                    'Cannot make orthogonal {}. '
                    'shape = {}, interpreted as '
                    '{}-dim input and {}-dim output.'.format(
                        self.mode, array.shape, in_dim, out_dim))
            transpose = in_dim > out_dim
            if self.rng is None:
                a = numpy.random.normal(size=(out_dim, in_dim))
            else:
                a_tmp = self.rng.normal(size=(out_dim, in_dim))
                a = numpy.empty(a_tmp.shape, dtype=a_tmp.dtype)
                backend.copyto(a, a_tmp)
            if transpose:
                a = a.T
            # cupy.linalg.qr requires cusolver in CUDA 8+
            q, r = numpy.linalg.qr(a)
            q *= numpy.copysign(self.scale, numpy.diag(r))
            if transpose:
                q = q.T
            backend.copyto(array, q.reshape(array.shape).astype(
                array.dtype, copy=False)) 
开发者ID:chainer,项目名称:chainer,代码行数:42,代码来源:orthogonal.py

示例13: _boundary_inputs

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import copysign [as 别名]
def _boundary_inputs(boundary, rtol, atol):
    left = boundary * (1 - numpy.copysign(rtol, boundary)) - atol
    right = boundary * (1 + numpy.copysign(rtol, boundary)) + atol
    return [left, boundary, right] 
开发者ID:cupy,项目名称:cupy,代码行数:6,代码来源:test_erf.py

示例14: opposite_side_port_out

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import copysign [as 别名]
def opposite_side_port_out(self):
        return self.port.parallel_offset(np.copysign(2 * self.radius + self.vertical_race_length, self.opposite_gap)
                                         + self._offset + self._offset_opposite) 
开发者ID:HelgeGehring,项目名称:gdshelpers,代码行数:5,代码来源:resonator.py

示例15: opposite_side_port_in

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import copysign [as 别名]
def opposite_side_port_in(self):
        return self._origin_port.parallel_offset(
            np.copysign(2 * self.radius + self.vertical_race_length, self.opposite_gap)
            + self._offset + self._offset_opposite).inverted_direction

    # Conventional naming of ports 
开发者ID:HelgeGehring,项目名称:gdshelpers,代码行数:8,代码来源:resonator.py


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